Generated by Cython 3.0.2

Yellow lines hint at Python interaction.
Click on a line that starts with a "+" to see the C code that Cython generated for it.

Raw output: ccm.c

+001: # cython: infer_types=True, wraparound=False, nonecheck=False, boundscheck=False, cdivision=True, language_level=3, profile=True, autogen_pxd=True
  __pyx_t_7 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_7) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
 002: 
+003: import numpy as np
  __pyx_t_7 = __Pyx_ImportDottedModule(__pyx_n_s_numpy, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_np, __pyx_t_7) < 0) __PYX_ERR(0, 3, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
 004: cimport numpy as np
 005: 
 006: import cython
 007: from libc.math cimport pi
 008: 
 009: from .ccm_helper_functions cimport _check_even_square, _make_even_square
 010: from .pearson_correlation cimport _calculate_ppmcc
 011: 
 012: from ..transform.interpolation_catmull_rom cimport Interpolator
 013: 
+014: def calculate_ccm(np.ndarray img_stack, int ref):
/* Python wrapper */
static PyObject *__pyx_pw_7nanopyx_4core_8analysis_3ccm_1calculate_ccm(PyObject *__pyx_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
PyDoc_STRVAR(__pyx_doc_7nanopyx_4core_8analysis_3ccm_calculate_ccm, "\n    Function used to generate a cross correlation matrix of an image stack.\n    Cross correlation is calculated using either the first image of the stack or the previous image.\n    Cross correlation values are normalized by the minimum and maximum Pearson's correlation between the two\n    images.\n    :param img_stack: numpy array with shape (t, y, x)\n    :param ref: either 0 or 1, 0 is used to calculate the ccm based on the first frame, 1 used to calculate based on the previous frame\n    :return: numpy array with shape (t, y, x), corresponding to the cross correlation matrix\n    ");
static PyMethodDef __pyx_mdef_7nanopyx_4core_8analysis_3ccm_1calculate_ccm = {"calculate_ccm", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_7nanopyx_4core_8analysis_3ccm_1calculate_ccm, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_7nanopyx_4core_8analysis_3ccm_calculate_ccm};
static PyObject *__pyx_pw_7nanopyx_4core_8analysis_3ccm_1calculate_ccm(PyObject *__pyx_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
  PyArrayObject *__pyx_v_img_stack = 0;
  int __pyx_v_ref;
  #if !CYTHON_METH_FASTCALL
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  #endif
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("calculate_ccm (wrapper)", 0);
  #if !CYTHON_METH_FASTCALL
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args);
  if (unlikely((__pyx_nargs < 0))) __PYX_ERR(0, 14, __pyx_L3_error)
  #endif
  #endif
  __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
  {
    PyObject **__pyx_pyargnames[] = {&__pyx_n_s_img_stack,&__pyx_n_s_ref,0};
  PyObject* values[2] = {0,0};
    if (__pyx_kwds) {
      Py_ssize_t kw_args;
      switch (__pyx_nargs) {
        case  2: values[1] = __Pyx_Arg_FASTCALL(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = __Pyx_NumKwargs_FASTCALL(__pyx_kwds);
      switch (__pyx_nargs) {
        case  0:
        if (likely((values[0] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_img_stack)) != 0)) {
          (void)__Pyx_Arg_NewRef_FASTCALL(values[0]);
          kw_args--;
        }
        else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 14, __pyx_L3_error)
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_ref)) != 0)) {
          (void)__Pyx_Arg_NewRef_FASTCALL(values[1]);
          kw_args--;
        }
        else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 14, __pyx_L3_error)
        else {
          __Pyx_RaiseArgtupleInvalid("calculate_ccm", 1, 2, 2, 1); __PYX_ERR(0, 14, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        const Py_ssize_t kwd_pos_args = __pyx_nargs;
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "calculate_ccm") < 0)) __PYX_ERR(0, 14, __pyx_L3_error)
      }
    } else if (unlikely(__pyx_nargs != 2)) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
      values[1] = __Pyx_Arg_FASTCALL(__pyx_args, 1);
    }
    __pyx_v_img_stack = ((PyArrayObject *)values[0]);
    __pyx_v_ref = __Pyx_PyInt_As_int(values[1]); if (unlikely((__pyx_v_ref == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 14, __pyx_L3_error)
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("calculate_ccm", 1, 2, 2, __pyx_nargs); __PYX_ERR(0, 14, __pyx_L3_error)
  goto __pyx_L3_error;
  __pyx_L3_error:;
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_AddTraceback("nanopyx.core.analysis.ccm.calculate_ccm", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_img_stack), __pyx_ptype_5numpy_ndarray, 1, "img_stack", 0))) __PYX_ERR(0, 14, __pyx_L1_error)
  __pyx_r = __pyx_pf_7nanopyx_4core_8analysis_3ccm_calculate_ccm(__pyx_self, __pyx_v_img_stack, __pyx_v_ref);
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_7nanopyx_4core_8analysis_3ccm_calculate_ccm(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_img_stack, int __pyx_v_ref) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_TraceFrameInit(__pyx_codeobj__11)
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("calculate_ccm", 0);
  __Pyx_TraceCall("calculate_ccm", __pyx_f[0], 14, 0, __PYX_ERR(0, 14, __pyx_L1_error));
/* … */
  /* function exit code */
  __pyx_L1_error:;
  __PYX_XCLEAR_MEMVIEW(&__pyx_t_1, 1);
  __PYX_XCLEAR_MEMVIEW(&__pyx_t_2, 1);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("nanopyx.core.analysis.ccm.calculate_ccm", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
/* … */
  __pyx_tuple__29 = PyTuple_Pack(2, __pyx_n_s_img_stack, __pyx_n_s_ref); if (unlikely(!__pyx_tuple__29)) __PYX_ERR(0, 14, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__29);
  __Pyx_GIVEREF(__pyx_tuple__29);
/* … */
  __pyx_t_7 = __Pyx_CyFunction_New(&__pyx_mdef_7nanopyx_4core_8analysis_3ccm_1calculate_ccm, 0, __pyx_n_s_calculate_ccm, NULL, __pyx_n_s_nanopyx_core_analysis_ccm, __pyx_d, ((PyObject *)__pyx_codeobj__11)); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 14, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_calculate_ccm, __pyx_t_7) < 0) __PYX_ERR(0, 14, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_codeobj__11 = (PyObject*)__Pyx_PyCode_New(2, 0, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__29, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_nanopyx_core_analysis_ccm_py, __pyx_n_s_calculate_ccm, 14, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__11)) __PYX_ERR(0, 14, __pyx_L1_error)
 015:     """
 016:     Function used to generate a cross correlation matrix of an image stack.
 017:     Cross correlation is calculated using either the first image of the stack or the previous image.
 018:     Cross correlation values are normalized by the minimum and maximum Pearson's correlation between the two
 019:     images.
 020:     :param img_stack: numpy array with shape (t, y, x)
 021:     :param ref: either 0 or 1, 0 is used to calculate the ccm based on the first frame, 1 used to calculate based on the previous frame
 022:     :return: numpy array with shape (t, y, x), corresponding to the cross correlation matrix
 023:     """
+024:     return _calculate_ccm(img_stack, ref)
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_to_MemoryviewSlice_dsdsds_float(((PyObject *)__pyx_v_img_stack), PyBUF_WRITABLE); if (unlikely(!__pyx_t_1.memview)) __PYX_ERR(0, 24, __pyx_L1_error)
  __pyx_t_2 = __pyx_f_7nanopyx_4core_8analysis_3ccm__calculate_ccm(__pyx_t_1, __pyx_v_ref); if (unlikely(!__pyx_t_2.memview)) __PYX_ERR(0, 24, __pyx_L1_error)
  __PYX_XCLEAR_MEMVIEW(&__pyx_t_1, 1);
  __pyx_t_1.memview = NULL; __pyx_t_1.data = NULL;
  __pyx_t_3 = __pyx_memoryview_fromslice(__pyx_t_2, 3, (PyObject *(*)(char *)) __pyx_memview_get_float, (int (*)(char *, PyObject *)) __pyx_memview_set_float, 0);; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 24, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __PYX_XCLEAR_MEMVIEW(&__pyx_t_2, 1);
  __pyx_t_2.memview = NULL; __pyx_t_2.data = NULL;
  __pyx_r = __pyx_t_3;
  __pyx_t_3 = 0;
  goto __pyx_L0;
 025: 
 026: 
+027: cdef float[:, :, :] _calculate_ccm(float[:, :, :] img_stack, int ref):
static __Pyx_memviewslice __pyx_f_7nanopyx_4core_8analysis_3ccm__calculate_ccm(__Pyx_memviewslice __pyx_v_img_stack, int __pyx_v_ref) {
  int __pyx_v_stack_w;
  int __pyx_v_stack_h;
  int __pyx_v_stack_n;
  __Pyx_memviewslice __pyx_v_ccm = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_img_ref = { 0, 0, { 0 }, { 0 }, { 0 } };
  int __pyx_v_i;
  int __pyx_v__n;
  __Pyx_memviewslice __pyx_r = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_calculate_ccm", 0);
  __Pyx_TraceCall("_calculate_ccm", __pyx_f[0], 27, 0, __PYX_ERR(0, 27, __pyx_L1_error));
  __PYX_INC_MEMVIEW(&__pyx_v_img_stack, 1);
/* … */
  /* function exit code */
  __pyx_L1_error:;
  __PYX_XCLEAR_MEMVIEW(&__pyx_t_3, 1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __PYX_XCLEAR_MEMVIEW(&__pyx_t_12, 1);
  __PYX_XCLEAR_MEMVIEW(&__pyx_t_16, 1);
  __pyx_r.data = NULL;
  __pyx_r.memview = NULL;
  __Pyx_AddTraceback("nanopyx.core.analysis.ccm._calculate_ccm", __pyx_clineno, __pyx_lineno, __pyx_filename);
  goto __pyx_L2;
  __pyx_L0:;
  if (unlikely(!__pyx_r.memview)) {
    PyErr_SetString(PyExc_TypeError, "Memoryview return value is not initialized");
  }
  __pyx_L2:;
  __PYX_XCLEAR_MEMVIEW(&__pyx_v_ccm, 1);
  __PYX_XCLEAR_MEMVIEW(&__pyx_v_img_ref, 1);
  __PYX_XCLEAR_MEMVIEW(&__pyx_v_img_stack, 1);
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
 028: 
+029:     if not _check_even_square(img_stack):
  __pyx_t_1 = __pyx_f_7nanopyx_4core_8analysis_20ccm_helper_functions__check_even_square(__pyx_v_img_stack); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 29, __pyx_L1_error)
  __pyx_t_2 = (!__pyx_t_1);
  if (__pyx_t_2) {
/* … */
  }
+030:         img_stack = _make_even_square(img_stack)
    __pyx_t_3 = __pyx_f_7nanopyx_4core_8analysis_20ccm_helper_functions__make_even_square(__pyx_v_img_stack); if (unlikely(!__pyx_t_3.memview)) __PYX_ERR(0, 30, __pyx_L1_error)
    __PYX_XCLEAR_MEMVIEW(&__pyx_v_img_stack, 1);
    __pyx_v_img_stack = __pyx_t_3;
    __pyx_t_3.memview = NULL;
    __pyx_t_3.data = NULL;
 031: 
+032:     cdef int stack_w = img_stack.shape[2]
  __pyx_v_stack_w = (__pyx_v_img_stack.shape[2]);
+033:     cdef int stack_h = img_stack.shape[1]
  __pyx_v_stack_h = (__pyx_v_img_stack.shape[1]);
+034:     cdef int stack_n = img_stack.shape[0]
  __pyx_v_stack_n = (__pyx_v_img_stack.shape[0]);
+035:     cdef float[:, :, :] ccm = np.empty((stack_n, stack_h, stack_w), dtype=np.float32)
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 35, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_empty); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 35, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_stack_n); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 35, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_stack_h); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 35, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_7 = __Pyx_PyInt_From_int(__pyx_v_stack_w); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 35, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_8 = PyTuple_New(3); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 35, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_GIVEREF(__pyx_t_4);
  if (__Pyx_PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_4)) __PYX_ERR(0, 35, __pyx_L1_error);
  __Pyx_GIVEREF(__pyx_t_6);
  if (__Pyx_PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_6)) __PYX_ERR(0, 35, __pyx_L1_error);
  __Pyx_GIVEREF(__pyx_t_7);
  if (__Pyx_PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_t_7)) __PYX_ERR(0, 35, __pyx_L1_error);
  __pyx_t_4 = 0;
  __pyx_t_6 = 0;
  __pyx_t_7 = 0;
  __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 35, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_8);
  if (__Pyx_PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_8)) __PYX_ERR(0, 35, __pyx_L1_error);
  __pyx_t_8 = 0;
  __pyx_t_8 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 35, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 35, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_float32); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 35, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (PyDict_SetItem(__pyx_t_8, __pyx_n_s_dtype, __pyx_t_4) < 0) __PYX_ERR(0, 35, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_7, __pyx_t_8); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 35, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_t_3 = __Pyx_PyObject_to_MemoryviewSlice_dsdsds_float(__pyx_t_4, PyBUF_WRITABLE); if (unlikely(!__pyx_t_3.memview)) __PYX_ERR(0, 35, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_v_ccm = __pyx_t_3;
  __pyx_t_3.memview = NULL;
  __pyx_t_3.data = NULL;
 036: 
 037:     cdef float[:, :] img_ref
 038:     cdef int i, _n
 039: 
+040:     for i in range(stack_n):
  __pyx_t_9 = __pyx_v_stack_n;
  __pyx_t_10 = __pyx_t_9;
  for (__pyx_t_11 = 0; __pyx_t_11 < __pyx_t_10; __pyx_t_11+=1) {
    __pyx_v_i = __pyx_t_11;
+041:         if ref == 0:
    __pyx_t_2 = (__pyx_v_ref == 0);
    if (__pyx_t_2) {
/* … */
      goto __pyx_L6;
    }
+042:             img_ref = img_stack[0]
      __pyx_t_12.data = __pyx_v_img_stack.data;
      __pyx_t_12.memview = __pyx_v_img_stack.memview;
      __PYX_INC_MEMVIEW(&__pyx_t_12, 1);
      {
    Py_ssize_t __pyx_tmp_idx = 0;
    Py_ssize_t __pyx_tmp_stride = __pyx_v_img_stack.strides[0];
        __pyx_t_12.data += __pyx_tmp_idx * __pyx_tmp_stride;
}

__pyx_t_12.shape[0] = __pyx_v_img_stack.shape[1];
__pyx_t_12.strides[0] = __pyx_v_img_stack.strides[1];
    __pyx_t_12.suboffsets[0] = -1;

__pyx_t_12.shape[1] = __pyx_v_img_stack.shape[2];
__pyx_t_12.strides[1] = __pyx_v_img_stack.strides[2];
    __pyx_t_12.suboffsets[1] = -1;

__PYX_XCLEAR_MEMVIEW(&__pyx_v_img_ref, 1);
      __pyx_v_img_ref = __pyx_t_12;
      __pyx_t_12.memview = NULL;
      __pyx_t_12.data = NULL;
 043:         else:
+044:             _n = max(0, i-1)
    /*else*/ {
      __pyx_t_13 = (__pyx_v_i - 1);
      __pyx_t_14 = 0;
      __pyx_t_2 = (__pyx_t_13 > __pyx_t_14);
      if (__pyx_t_2) {
        __pyx_t_15 = __pyx_t_13;
      } else {
        __pyx_t_15 = __pyx_t_14;
      }
      __pyx_v__n = __pyx_t_15;
+045:             img_ref = img_stack[_n]
      __pyx_t_12.data = __pyx_v_img_stack.data;
      __pyx_t_12.memview = __pyx_v_img_stack.memview;
      __PYX_INC_MEMVIEW(&__pyx_t_12, 1);
      {
    Py_ssize_t __pyx_tmp_idx = __pyx_v__n;
    Py_ssize_t __pyx_tmp_stride = __pyx_v_img_stack.strides[0];
        __pyx_t_12.data += __pyx_tmp_idx * __pyx_tmp_stride;
}

__pyx_t_12.shape[0] = __pyx_v_img_stack.shape[1];
__pyx_t_12.strides[0] = __pyx_v_img_stack.strides[1];
    __pyx_t_12.suboffsets[0] = -1;

__pyx_t_12.shape[1] = __pyx_v_img_stack.shape[2];
__pyx_t_12.strides[1] = __pyx_v_img_stack.strides[2];
    __pyx_t_12.suboffsets[1] = -1;

__PYX_XCLEAR_MEMVIEW(&__pyx_v_img_ref, 1);
      __pyx_v_img_ref = __pyx_t_12;
      __pyx_t_12.memview = NULL;
      __pyx_t_12.data = NULL;
    }
    __pyx_L6:;
+046:         ccm[i] = _calculate_slice_ccm(img_ref, img_stack[i])
    __pyx_t_12.data = __pyx_v_img_stack.data;
    __pyx_t_12.memview = __pyx_v_img_stack.memview;
    __PYX_INC_MEMVIEW(&__pyx_t_12, 1);
    {
    Py_ssize_t __pyx_tmp_idx = __pyx_v_i;
    Py_ssize_t __pyx_tmp_stride = __pyx_v_img_stack.strides[0];
        __pyx_t_12.data += __pyx_tmp_idx * __pyx_tmp_stride;
}

__pyx_t_12.shape[0] = __pyx_v_img_stack.shape[1];
__pyx_t_12.strides[0] = __pyx_v_img_stack.strides[1];
    __pyx_t_12.suboffsets[0] = -1;

__pyx_t_12.shape[1] = __pyx_v_img_stack.shape[2];
__pyx_t_12.strides[1] = __pyx_v_img_stack.strides[2];
    __pyx_t_12.suboffsets[1] = -1;

__pyx_t_16 = __pyx_f_7nanopyx_4core_8analysis_3ccm__calculate_slice_ccm(__pyx_v_img_ref, __pyx_t_12); if (unlikely(!__pyx_t_16.memview)) __PYX_ERR(0, 46, __pyx_L1_error)
    __PYX_XCLEAR_MEMVIEW(&__pyx_t_12, 1);
    __pyx_t_12.memview = NULL; __pyx_t_12.data = NULL;
    __pyx_t_12.data = __pyx_v_ccm.data;
    __pyx_t_12.memview = __pyx_v_ccm.memview;
    __PYX_INC_MEMVIEW(&__pyx_t_12, 1);
    {
    Py_ssize_t __pyx_tmp_idx = __pyx_v_i;
    Py_ssize_t __pyx_tmp_stride = __pyx_v_ccm.strides[0];
        __pyx_t_12.data += __pyx_tmp_idx * __pyx_tmp_stride;
}

__pyx_t_12.shape[0] = __pyx_v_ccm.shape[1];
__pyx_t_12.strides[0] = __pyx_v_ccm.strides[1];
    __pyx_t_12.suboffsets[0] = -1;

__pyx_t_12.shape[1] = __pyx_v_ccm.shape[2];
__pyx_t_12.strides[1] = __pyx_v_ccm.strides[2];
    __pyx_t_12.suboffsets[1] = -1;

if (unlikely((__pyx_memoryview_copy_contents(__pyx_t_16, __pyx_t_12, 2, 2, 0) < 0))) __PYX_ERR(0, 46, __pyx_L1_error)
    __PYX_XCLEAR_MEMVIEW(&__pyx_t_12, 1);
    __pyx_t_12.memview = NULL; __pyx_t_12.data = NULL;
    __PYX_XCLEAR_MEMVIEW(&__pyx_t_16, 1);
    __pyx_t_16.memview = NULL; __pyx_t_16.data = NULL;
  }
 047: 
+048:     return ccm
  __PYX_INC_MEMVIEW(&__pyx_v_ccm, 1);
  __pyx_r = __pyx_v_ccm;
  goto __pyx_L0;
 049: 
 050: 
+051: def calculate_ccm_from_ref(np.ndarray img_stack, np.ndarray img_ref):
/* Python wrapper */
static PyObject *__pyx_pw_7nanopyx_4core_8analysis_3ccm_3calculate_ccm_from_ref(PyObject *__pyx_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
PyDoc_STRVAR(__pyx_doc_7nanopyx_4core_8analysis_3ccm_2calculate_ccm_from_ref, "\n    Function used to generate a cross correlation matrix of an image stack.\n    Cross correlation is calculated using a static image frame.\n    Cross correlation values are normalized by the minimum and maximum Pearson's correlation between the two\n    images.\n    :param img_stack: numpy array with shape (t, y, x)\n    :param img_ref: numpy array with shape (y, x)\n    :return: numpy array with shape (t, y, x), corresponding to the cross correlation matrix\n    ");
static PyMethodDef __pyx_mdef_7nanopyx_4core_8analysis_3ccm_3calculate_ccm_from_ref = {"calculate_ccm_from_ref", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_7nanopyx_4core_8analysis_3ccm_3calculate_ccm_from_ref, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_7nanopyx_4core_8analysis_3ccm_2calculate_ccm_from_ref};
static PyObject *__pyx_pw_7nanopyx_4core_8analysis_3ccm_3calculate_ccm_from_ref(PyObject *__pyx_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
  PyArrayObject *__pyx_v_img_stack = 0;
  PyArrayObject *__pyx_v_img_ref = 0;
  #if !CYTHON_METH_FASTCALL
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  #endif
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("calculate_ccm_from_ref (wrapper)", 0);
  #if !CYTHON_METH_FASTCALL
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args);
  if (unlikely((__pyx_nargs < 0))) __PYX_ERR(0, 51, __pyx_L3_error)
  #endif
  #endif
  __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
  {
    PyObject **__pyx_pyargnames[] = {&__pyx_n_s_img_stack,&__pyx_n_s_img_ref,0};
  PyObject* values[2] = {0,0};
    if (__pyx_kwds) {
      Py_ssize_t kw_args;
      switch (__pyx_nargs) {
        case  2: values[1] = __Pyx_Arg_FASTCALL(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = __Pyx_NumKwargs_FASTCALL(__pyx_kwds);
      switch (__pyx_nargs) {
        case  0:
        if (likely((values[0] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_img_stack)) != 0)) {
          (void)__Pyx_Arg_NewRef_FASTCALL(values[0]);
          kw_args--;
        }
        else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 51, __pyx_L3_error)
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_img_ref)) != 0)) {
          (void)__Pyx_Arg_NewRef_FASTCALL(values[1]);
          kw_args--;
        }
        else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 51, __pyx_L3_error)
        else {
          __Pyx_RaiseArgtupleInvalid("calculate_ccm_from_ref", 1, 2, 2, 1); __PYX_ERR(0, 51, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        const Py_ssize_t kwd_pos_args = __pyx_nargs;
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "calculate_ccm_from_ref") < 0)) __PYX_ERR(0, 51, __pyx_L3_error)
      }
    } else if (unlikely(__pyx_nargs != 2)) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
      values[1] = __Pyx_Arg_FASTCALL(__pyx_args, 1);
    }
    __pyx_v_img_stack = ((PyArrayObject *)values[0]);
    __pyx_v_img_ref = ((PyArrayObject *)values[1]);
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("calculate_ccm_from_ref", 1, 2, 2, __pyx_nargs); __PYX_ERR(0, 51, __pyx_L3_error)
  goto __pyx_L3_error;
  __pyx_L3_error:;
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_AddTraceback("nanopyx.core.analysis.ccm.calculate_ccm_from_ref", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_img_stack), __pyx_ptype_5numpy_ndarray, 1, "img_stack", 0))) __PYX_ERR(0, 51, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_img_ref), __pyx_ptype_5numpy_ndarray, 1, "img_ref", 0))) __PYX_ERR(0, 51, __pyx_L1_error)
  __pyx_r = __pyx_pf_7nanopyx_4core_8analysis_3ccm_2calculate_ccm_from_ref(__pyx_self, __pyx_v_img_stack, __pyx_v_img_ref);
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_7nanopyx_4core_8analysis_3ccm_2calculate_ccm_from_ref(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_img_stack, PyArrayObject *__pyx_v_img_ref) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_TraceFrameInit(__pyx_codeobj__12)
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("calculate_ccm_from_ref", 0);
  __Pyx_TraceCall("calculate_ccm_from_ref", __pyx_f[0], 51, 0, __PYX_ERR(0, 51, __pyx_L1_error));
/* … */
  /* function exit code */
  __pyx_L1_error:;
  __PYX_XCLEAR_MEMVIEW(&__pyx_t_1, 1);
  __PYX_XCLEAR_MEMVIEW(&__pyx_t_2, 1);
  __PYX_XCLEAR_MEMVIEW(&__pyx_t_3, 1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("nanopyx.core.analysis.ccm.calculate_ccm_from_ref", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
/* … */
  __pyx_tuple__30 = PyTuple_Pack(2, __pyx_n_s_img_stack, __pyx_n_s_img_ref); if (unlikely(!__pyx_tuple__30)) __PYX_ERR(0, 51, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__30);
  __Pyx_GIVEREF(__pyx_tuple__30);
/* … */
  __pyx_t_7 = __Pyx_CyFunction_New(&__pyx_mdef_7nanopyx_4core_8analysis_3ccm_3calculate_ccm_from_ref, 0, __pyx_n_s_calculate_ccm_from_ref, NULL, __pyx_n_s_nanopyx_core_analysis_ccm, __pyx_d, ((PyObject *)__pyx_codeobj__12)); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 51, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_calculate_ccm_from_ref, __pyx_t_7) < 0) __PYX_ERR(0, 51, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_codeobj__12 = (PyObject*)__Pyx_PyCode_New(2, 0, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__30, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_nanopyx_core_analysis_ccm_py, __pyx_n_s_calculate_ccm_from_ref, 51, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__12)) __PYX_ERR(0, 51, __pyx_L1_error)
 052:     """
 053:     Function used to generate a cross correlation matrix of an image stack.
 054:     Cross correlation is calculated using a static image frame.
 055:     Cross correlation values are normalized by the minimum and maximum Pearson's correlation between the two
 056:     images.
 057:     :param img_stack: numpy array with shape (t, y, x)
 058:     :param img_ref: numpy array with shape (y, x)
 059:     :return: numpy array with shape (t, y, x), corresponding to the cross correlation matrix
 060:     """
+061:     return _calculate_ccm_from_ref(img_stack, img_ref)
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_to_MemoryviewSlice_dsdsds_float(((PyObject *)__pyx_v_img_stack), PyBUF_WRITABLE); if (unlikely(!__pyx_t_1.memview)) __PYX_ERR(0, 61, __pyx_L1_error)
  __pyx_t_2 = __Pyx_PyObject_to_MemoryviewSlice_dsds_float(((PyObject *)__pyx_v_img_ref), PyBUF_WRITABLE); if (unlikely(!__pyx_t_2.memview)) __PYX_ERR(0, 61, __pyx_L1_error)
  __pyx_t_3 = __pyx_f_7nanopyx_4core_8analysis_3ccm__calculate_ccm_from_ref(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3.memview)) __PYX_ERR(0, 61, __pyx_L1_error)
  __PYX_XCLEAR_MEMVIEW(&__pyx_t_1, 1);
  __pyx_t_1.memview = NULL; __pyx_t_1.data = NULL;
  __PYX_XCLEAR_MEMVIEW(&__pyx_t_2, 1);
  __pyx_t_2.memview = NULL; __pyx_t_2.data = NULL;
  __pyx_t_4 = __pyx_memoryview_fromslice(__pyx_t_3, 3, (PyObject *(*)(char *)) __pyx_memview_get_float, (int (*)(char *, PyObject *)) __pyx_memview_set_float, 0);; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 61, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __PYX_XCLEAR_MEMVIEW(&__pyx_t_3, 1);
  __pyx_t_3.memview = NULL; __pyx_t_3.data = NULL;
  __pyx_r = __pyx_t_4;
  __pyx_t_4 = 0;
  goto __pyx_L0;
 062: 
 063: 
 064: 
+065: cdef float[:, :, :] _calculate_ccm_from_ref(float[:, :, :] img_stack, float[:, :] img_ref):
static __Pyx_memviewslice __pyx_f_7nanopyx_4core_8analysis_3ccm__calculate_ccm_from_ref(__Pyx_memviewslice __pyx_v_img_stack, __Pyx_memviewslice __pyx_v_img_ref) {
  __Pyx_memviewslice __pyx_v_tmp = { 0, 0, { 0 }, { 0 }, { 0 } };
  int __pyx_v_stack_w;
  int __pyx_v_stack_h;
  int __pyx_v_stack_n;
  __Pyx_memviewslice __pyx_v_ccm = { 0, 0, { 0 }, { 0 }, { 0 } };
  int __pyx_v_i;
  __Pyx_memviewslice __pyx_r = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_calculate_ccm_from_ref", 0);
  __Pyx_TraceCall("_calculate_ccm_from_ref", __pyx_f[0], 65, 0, __PYX_ERR(0, 65, __pyx_L1_error));
  __PYX_INC_MEMVIEW(&__pyx_v_img_stack, 1);
  __PYX_INC_MEMVIEW(&__pyx_v_img_ref, 1);
/* … */
  /* function exit code */
  __pyx_L1_error:;
  __PYX_XCLEAR_MEMVIEW(&__pyx_t_3, 1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __PYX_XCLEAR_MEMVIEW(&__pyx_t_9, 1);
  __Pyx_XDECREF(__pyx_t_10);
  __PYX_XCLEAR_MEMVIEW(&__pyx_t_13, 1);
  __pyx_r.data = NULL;
  __pyx_r.memview = NULL;
  __Pyx_AddTraceback("nanopyx.core.analysis.ccm._calculate_ccm_from_ref", __pyx_clineno, __pyx_lineno, __pyx_filename);
  goto __pyx_L2;
  __pyx_L0:;
  if (unlikely(!__pyx_r.memview)) {
    PyErr_SetString(PyExc_TypeError, "Memoryview return value is not initialized");
  }
  __pyx_L2:;
  __PYX_XCLEAR_MEMVIEW(&__pyx_v_tmp, 1);
  __PYX_XCLEAR_MEMVIEW(&__pyx_v_ccm, 1);
  __PYX_XCLEAR_MEMVIEW(&__pyx_v_img_stack, 1);
  __PYX_XCLEAR_MEMVIEW(&__pyx_v_img_ref, 1);
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
 066: 
+067:     if not _check_even_square(img_stack):
  __pyx_t_1 = __pyx_f_7nanopyx_4core_8analysis_20ccm_helper_functions__check_even_square(__pyx_v_img_stack); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 67, __pyx_L1_error)
  __pyx_t_2 = (!__pyx_t_1);
  if (__pyx_t_2) {
/* … */
  }
+068:         img_stack = _make_even_square(img_stack)
    __pyx_t_3 = __pyx_f_7nanopyx_4core_8analysis_20ccm_helper_functions__make_even_square(__pyx_v_img_stack); if (unlikely(!__pyx_t_3.memview)) __PYX_ERR(0, 68, __pyx_L1_error)
    __PYX_XCLEAR_MEMVIEW(&__pyx_v_img_stack, 1);
    __pyx_v_img_stack = __pyx_t_3;
    __pyx_t_3.memview = NULL;
    __pyx_t_3.data = NULL;
 069: 
+070:     cdef float[:,:,:] tmp = np.array([img_ref])
  __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 70, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_array); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 70, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __pyx_memoryview_fromslice(__pyx_v_img_ref, 2, (PyObject *(*)(char *)) __pyx_memview_get_float, (int (*)(char *, PyObject *)) __pyx_memview_set_float, 0);; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 70, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_7 = PyList_New(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 70, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_5);
  if (__Pyx_PyList_SET_ITEM(__pyx_t_7, 0, __pyx_t_5)) __PYX_ERR(0, 70, __pyx_L1_error);
  __pyx_t_5 = 0;
  __pyx_t_5 = NULL;
  __pyx_t_8 = 0;
  #if CYTHON_UNPACK_METHODS
  if (unlikely(PyMethod_Check(__pyx_t_6))) {
    __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_6);
    if (likely(__pyx_t_5)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
      __Pyx_INCREF(__pyx_t_5);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_6, function);
      __pyx_t_8 = 1;
    }
  }
  #endif
  {
    PyObject *__pyx_callargs[2] = {__pyx_t_5, __pyx_t_7};
    __pyx_t_4 = __Pyx_PyObject_FastCall(__pyx_t_6, __pyx_callargs+1-__pyx_t_8, 1+__pyx_t_8);
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 70, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  }
  __pyx_t_3 = __Pyx_PyObject_to_MemoryviewSlice_dsdsds_float(__pyx_t_4, PyBUF_WRITABLE); if (unlikely(!__pyx_t_3.memview)) __PYX_ERR(0, 70, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_v_tmp = __pyx_t_3;
  __pyx_t_3.memview = NULL;
  __pyx_t_3.data = NULL;
+071:     if not _check_even_square(tmp):
  __pyx_t_2 = __pyx_f_7nanopyx_4core_8analysis_20ccm_helper_functions__check_even_square(__pyx_v_tmp); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 71, __pyx_L1_error)
  __pyx_t_1 = (!__pyx_t_2);
  if (__pyx_t_1) {
/* … */
  }
+072:         tmp = _make_even_square(tmp)
    __pyx_t_3 = __pyx_f_7nanopyx_4core_8analysis_20ccm_helper_functions__make_even_square(__pyx_v_tmp); if (unlikely(!__pyx_t_3.memview)) __PYX_ERR(0, 72, __pyx_L1_error)
    __PYX_XCLEAR_MEMVIEW(&__pyx_v_tmp, 1);
    __pyx_v_tmp = __pyx_t_3;
    __pyx_t_3.memview = NULL;
    __pyx_t_3.data = NULL;
+073:         img_ref = tmp[0]
    __pyx_t_9.data = __pyx_v_tmp.data;
    __pyx_t_9.memview = __pyx_v_tmp.memview;
    __PYX_INC_MEMVIEW(&__pyx_t_9, 1);
    {
    Py_ssize_t __pyx_tmp_idx = 0;
    Py_ssize_t __pyx_tmp_stride = __pyx_v_tmp.strides[0];
        __pyx_t_9.data += __pyx_tmp_idx * __pyx_tmp_stride;
}

__pyx_t_9.shape[0] = __pyx_v_tmp.shape[1];
__pyx_t_9.strides[0] = __pyx_v_tmp.strides[1];
    __pyx_t_9.suboffsets[0] = -1;

__pyx_t_9.shape[1] = __pyx_v_tmp.shape[2];
__pyx_t_9.strides[1] = __pyx_v_tmp.strides[2];
    __pyx_t_9.suboffsets[1] = -1;

__PYX_XCLEAR_MEMVIEW(&__pyx_v_img_ref, 1);
    __pyx_v_img_ref = __pyx_t_9;
    __pyx_t_9.memview = NULL;
    __pyx_t_9.data = NULL;
 074: 
+075:     cdef int stack_w = img_stack.shape[2]
  __pyx_v_stack_w = (__pyx_v_img_stack.shape[2]);
+076:     cdef int stack_h = img_stack.shape[1]
  __pyx_v_stack_h = (__pyx_v_img_stack.shape[1]);
+077:     cdef int stack_n = img_stack.shape[0]
  __pyx_v_stack_n = (__pyx_v_img_stack.shape[0]);
+078:     cdef float[:, :, :] ccm = np.empty((stack_n, stack_h, stack_w), dtype=np.float32)
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 78, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_empty); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 78, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_stack_n); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 78, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_7 = __Pyx_PyInt_From_int(__pyx_v_stack_h); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 78, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_stack_w); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 78, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_10 = PyTuple_New(3); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 78, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_10);
  __Pyx_GIVEREF(__pyx_t_4);
  if (__Pyx_PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_4)) __PYX_ERR(0, 78, __pyx_L1_error);
  __Pyx_GIVEREF(__pyx_t_7);
  if (__Pyx_PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_7)) __PYX_ERR(0, 78, __pyx_L1_error);
  __Pyx_GIVEREF(__pyx_t_5);
  if (__Pyx_PyTuple_SET_ITEM(__pyx_t_10, 2, __pyx_t_5)) __PYX_ERR(0, 78, __pyx_L1_error);
  __pyx_t_4 = 0;
  __pyx_t_7 = 0;
  __pyx_t_5 = 0;
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 78, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_10);
  if (__Pyx_PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_10)) __PYX_ERR(0, 78, __pyx_L1_error);
  __pyx_t_10 = 0;
  __pyx_t_10 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 78, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_10);
  __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_np); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 78, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_float32); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 78, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  if (PyDict_SetItem(__pyx_t_10, __pyx_n_s_dtype, __pyx_t_4) < 0) __PYX_ERR(0, 78, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_5, __pyx_t_10); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 78, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
  __pyx_t_3 = __Pyx_PyObject_to_MemoryviewSlice_dsdsds_float(__pyx_t_4, PyBUF_WRITABLE); if (unlikely(!__pyx_t_3.memview)) __PYX_ERR(0, 78, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_v_ccm = __pyx_t_3;
  __pyx_t_3.memview = NULL;
  __pyx_t_3.data = NULL;
 079: 
+080:     for i in range(stack_n):
  __pyx_t_8 = __pyx_v_stack_n;
  __pyx_t_11 = __pyx_t_8;
  for (__pyx_t_12 = 0; __pyx_t_12 < __pyx_t_11; __pyx_t_12+=1) {
    __pyx_v_i = __pyx_t_12;
+081:         ccm[i] = _calculate_slice_ccm(img_ref, img_stack[i])
    __pyx_t_9.data = __pyx_v_img_stack.data;
    __pyx_t_9.memview = __pyx_v_img_stack.memview;
    __PYX_INC_MEMVIEW(&__pyx_t_9, 1);
    {
    Py_ssize_t __pyx_tmp_idx = __pyx_v_i;
    Py_ssize_t __pyx_tmp_stride = __pyx_v_img_stack.strides[0];
        __pyx_t_9.data += __pyx_tmp_idx * __pyx_tmp_stride;
}

__pyx_t_9.shape[0] = __pyx_v_img_stack.shape[1];
__pyx_t_9.strides[0] = __pyx_v_img_stack.strides[1];
    __pyx_t_9.suboffsets[0] = -1;

__pyx_t_9.shape[1] = __pyx_v_img_stack.shape[2];
__pyx_t_9.strides[1] = __pyx_v_img_stack.strides[2];
    __pyx_t_9.suboffsets[1] = -1;

__pyx_t_13 = __pyx_f_7nanopyx_4core_8analysis_3ccm__calculate_slice_ccm(__pyx_v_img_ref, __pyx_t_9); if (unlikely(!__pyx_t_13.memview)) __PYX_ERR(0, 81, __pyx_L1_error)
    __PYX_XCLEAR_MEMVIEW(&__pyx_t_9, 1);
    __pyx_t_9.memview = NULL; __pyx_t_9.data = NULL;
    __pyx_t_9.data = __pyx_v_ccm.data;
    __pyx_t_9.memview = __pyx_v_ccm.memview;
    __PYX_INC_MEMVIEW(&__pyx_t_9, 1);
    {
    Py_ssize_t __pyx_tmp_idx = __pyx_v_i;
    Py_ssize_t __pyx_tmp_stride = __pyx_v_ccm.strides[0];
        __pyx_t_9.data += __pyx_tmp_idx * __pyx_tmp_stride;
}

__pyx_t_9.shape[0] = __pyx_v_ccm.shape[1];
__pyx_t_9.strides[0] = __pyx_v_ccm.strides[1];
    __pyx_t_9.suboffsets[0] = -1;

__pyx_t_9.shape[1] = __pyx_v_ccm.shape[2];
__pyx_t_9.strides[1] = __pyx_v_ccm.strides[2];
    __pyx_t_9.suboffsets[1] = -1;

if (unlikely((__pyx_memoryview_copy_contents(__pyx_t_13, __pyx_t_9, 2, 2, 0) < 0))) __PYX_ERR(0, 81, __pyx_L1_error)
    __PYX_XCLEAR_MEMVIEW(&__pyx_t_9, 1);
    __pyx_t_9.memview = NULL; __pyx_t_9.data = NULL;
    __PYX_XCLEAR_MEMVIEW(&__pyx_t_13, 1);
    __pyx_t_13.memview = NULL; __pyx_t_13.data = NULL;
  }
 082: 
+083:     return ccm
  __PYX_INC_MEMVIEW(&__pyx_v_ccm, 1);
  __pyx_r = __pyx_v_ccm;
  goto __pyx_L0;
 084: 
 085: 
+086: cdef float[:, :] _calculate_slice_ccm(float[:, :] img_ref, float[:, :] img_slice):
static __Pyx_memviewslice __pyx_f_7nanopyx_4core_8analysis_3ccm__calculate_slice_ccm(__Pyx_memviewslice __pyx_v_img_ref, __Pyx_memviewslice __pyx_v_img_slice) {
  __Pyx_memviewslice __pyx_v_ccm_slice = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_r = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_calculate_slice_ccm", 0);
  __Pyx_TraceCall("_calculate_slice_ccm", __pyx_f[0], 86, 0, __PYX_ERR(0, 86, __pyx_L1_error));
/* … */
  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_XDECREF(__pyx_t_11);
  __Pyx_XDECREF(__pyx_t_12);
  __PYX_XCLEAR_MEMVIEW(&__pyx_t_13, 1);
  __pyx_r.data = NULL;
  __pyx_r.memview = NULL;
  __Pyx_AddTraceback("nanopyx.core.analysis.ccm._calculate_slice_ccm", __pyx_clineno, __pyx_lineno, __pyx_filename);
  goto __pyx_L2;
  __pyx_L0:;
  if (unlikely(!__pyx_r.memview)) {
    PyErr_SetString(PyExc_TypeError, "Memoryview return value is not initialized");
  }
  __pyx_L2:;
  __PYX_XCLEAR_MEMVIEW(&__pyx_v_ccm_slice, 1);
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
+087:     cdef float[:, :] ccm_slice = np.fft.fftshift(np.fft.ifft2(np.fft.fft2(img_ref) * np.fft.fft2(img_slice).conj())).real.astype(np.float32)
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 87, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_fft); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 87, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_fftshift); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 87, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 87, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_fft); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 87, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_ifft2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 87, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_np); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 87, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_fft); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 87, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_fft2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 87, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_t_8 = __pyx_memoryview_fromslice(__pyx_v_img_ref, 2, (PyObject *(*)(char *)) __pyx_memview_get_float, (int (*)(char *, PyObject *)) __pyx_memview_set_float, 0);; if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 87, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_9 = NULL;
  __pyx_t_10 = 0;
  #if CYTHON_UNPACK_METHODS
  if (likely(PyMethod_Check(__pyx_t_7))) {
    __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_7);
    if (likely(__pyx_t_9)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
      __Pyx_INCREF(__pyx_t_9);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_7, function);
      __pyx_t_10 = 1;
    }
  }
  #endif
  {
    PyObject *__pyx_callargs[2] = {__pyx_t_9, __pyx_t_8};
    __pyx_t_6 = __Pyx_PyObject_FastCall(__pyx_t_7, __pyx_callargs+1-__pyx_t_10, 1+__pyx_t_10);
    __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 87, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  }
  __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_np); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 87, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_fft); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 87, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_11);
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_fft2); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 87, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
  __pyx_t_11 = __pyx_memoryview_fromslice(__pyx_v_img_slice, 2, (PyObject *(*)(char *)) __pyx_memview_get_float, (int (*)(char *, PyObject *)) __pyx_memview_set_float, 0);; if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 87, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_11);
  __pyx_t_12 = NULL;
  __pyx_t_10 = 0;
  #if CYTHON_UNPACK_METHODS
  if (likely(PyMethod_Check(__pyx_t_9))) {
    __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_9);
    if (likely(__pyx_t_12)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
      __Pyx_INCREF(__pyx_t_12);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_9, function);
      __pyx_t_10 = 1;
    }
  }
  #endif
  {
    PyObject *__pyx_callargs[2] = {__pyx_t_12, __pyx_t_11};
    __pyx_t_8 = __Pyx_PyObject_FastCall(__pyx_t_9, __pyx_callargs+1-__pyx_t_10, 1+__pyx_t_10);
    __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
    __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
    if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 87, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  }
  __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_conj); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 87, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_t_8 = NULL;
  __pyx_t_10 = 0;
  #if CYTHON_UNPACK_METHODS
  if (likely(PyMethod_Check(__pyx_t_9))) {
    __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_9);
    if (likely(__pyx_t_8)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
      __Pyx_INCREF(__pyx_t_8);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_9, function);
      __pyx_t_10 = 1;
    }
  }
  #endif
  {
    PyObject *__pyx_callargs[1] = {__pyx_t_8, };
    __pyx_t_7 = __Pyx_PyObject_FastCall(__pyx_t_9, __pyx_callargs+1-__pyx_t_10, 0+__pyx_t_10);
    __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
    if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 87, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  }
  __pyx_t_9 = PyNumber_Multiply(__pyx_t_6, __pyx_t_7); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 87, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = NULL;
  __pyx_t_10 = 0;
  #if CYTHON_UNPACK_METHODS
  if (likely(PyMethod_Check(__pyx_t_5))) {
    __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_5);
    if (likely(__pyx_t_7)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
      __Pyx_INCREF(__pyx_t_7);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_5, function);
      __pyx_t_10 = 1;
    }
  }
  #endif
  {
    PyObject *__pyx_callargs[2] = {__pyx_t_7, __pyx_t_9};
    __pyx_t_4 = __Pyx_PyObject_FastCall(__pyx_t_5, __pyx_callargs+1-__pyx_t_10, 1+__pyx_t_10);
    __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 87, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  }
  __pyx_t_5 = NULL;
  __pyx_t_10 = 0;
  #if CYTHON_UNPACK_METHODS
  if (likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_5)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_5);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
      __pyx_t_10 = 1;
    }
  }
  #endif
  {
    PyObject *__pyx_callargs[2] = {__pyx_t_5, __pyx_t_4};
    __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_10, 1+__pyx_t_10);
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 87, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  }
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_real); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 87, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_astype); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 87, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 87, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_float32); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 87, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = NULL;
  __pyx_t_10 = 0;
  #if CYTHON_UNPACK_METHODS
  if (likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
      __pyx_t_10 = 1;
    }
  }
  #endif
  {
    PyObject *__pyx_callargs[2] = {__pyx_t_3, __pyx_t_4};
    __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_2, __pyx_callargs+1-__pyx_t_10, 1+__pyx_t_10);
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 87, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  }
  __pyx_t_13 = __Pyx_PyObject_to_MemoryviewSlice_dsds_float(__pyx_t_1, PyBUF_WRITABLE); if (unlikely(!__pyx_t_13.memview)) __PYX_ERR(0, 87, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_ccm_slice = __pyx_t_13;
  __pyx_t_13.memview = NULL;
  __pyx_t_13.data = NULL;
+088:     ccm_slice = ccm_slice[::-1, ::-1]
  __pyx_t_13.data = __pyx_v_ccm_slice.data;
  __pyx_t_13.memview = __pyx_v_ccm_slice.memview;
  __PYX_INC_MEMVIEW(&__pyx_t_13, 1);
  __pyx_t_10 = -1;
  if (unlikely(__pyx_memoryview_slice_memviewslice(
    &__pyx_t_13,
    __pyx_v_ccm_slice.shape[0], __pyx_v_ccm_slice.strides[0], __pyx_v_ccm_slice.suboffsets[0],
    0,
    0,
    &__pyx_t_10,
    0,
    0,
    -1L,
    0,
    0,
    1,
    1) < 0))
{
    __PYX_ERR(0, 88, __pyx_L1_error)
}

if (unlikely(__pyx_memoryview_slice_memviewslice(
    &__pyx_t_13,
    __pyx_v_ccm_slice.shape[1], __pyx_v_ccm_slice.strides[1], __pyx_v_ccm_slice.suboffsets[1],
    1,
    1,
    &__pyx_t_10,
    0,
    0,
    -1L,
    0,
    0,
    1,
    1) < 0))
{
    __PYX_ERR(0, 88, __pyx_L1_error)
}

__PYX_XCLEAR_MEMVIEW(&__pyx_v_ccm_slice, 1);
  __pyx_v_ccm_slice = __pyx_t_13;
  __pyx_t_13.memview = NULL;
  __pyx_t_13.data = NULL;
+089:     _normalize_ccm(img_ref, img_slice, ccm_slice)
  __pyx_f_7nanopyx_4core_8analysis_3ccm__normalize_ccm(__pyx_v_img_ref, __pyx_v_img_slice, __pyx_v_ccm_slice); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 89, __pyx_L1_error)
 090: 
+091:     return ccm_slice[0:ccm_slice.shape[0], 0:ccm_slice.shape[1]]
  __pyx_t_13.data = __pyx_v_ccm_slice.data;
  __pyx_t_13.memview = __pyx_v_ccm_slice.memview;
  __PYX_INC_MEMVIEW(&__pyx_t_13, 1);
  __pyx_t_10 = -1;
  if (unlikely(__pyx_memoryview_slice_memviewslice(
    &__pyx_t_13,
    __pyx_v_ccm_slice.shape[0], __pyx_v_ccm_slice.strides[0], __pyx_v_ccm_slice.suboffsets[0],
    0,
    0,
    &__pyx_t_10,
    0,
    (__pyx_v_ccm_slice.shape[0]),
    0,
    1,
    1,
    0,
    1) < 0))
{
    __PYX_ERR(0, 91, __pyx_L1_error)
}

if (unlikely(__pyx_memoryview_slice_memviewslice(
    &__pyx_t_13,
    __pyx_v_ccm_slice.shape[1], __pyx_v_ccm_slice.strides[1], __pyx_v_ccm_slice.suboffsets[1],
    1,
    1,
    &__pyx_t_10,
    0,
    (__pyx_v_ccm_slice.shape[1]),
    0,
    1,
    1,
    0,
    1) < 0))
{
    __PYX_ERR(0, 91, __pyx_L1_error)
}

__pyx_r = __pyx_t_13;
  __pyx_t_13.memview = NULL;
  __pyx_t_13.data = NULL;
  goto __pyx_L0;
 092: 
+093: def calculate_slice_ccm(np.ndarray img_ref, np.ndarray img_slice):
/* Python wrapper */
static PyObject *__pyx_pw_7nanopyx_4core_8analysis_3ccm_5calculate_slice_ccm(PyObject *__pyx_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
static PyMethodDef __pyx_mdef_7nanopyx_4core_8analysis_3ccm_5calculate_slice_ccm = {"calculate_slice_ccm", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_7nanopyx_4core_8analysis_3ccm_5calculate_slice_ccm, __Pyx_METH_FASTCALL|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_7nanopyx_4core_8analysis_3ccm_5calculate_slice_ccm(PyObject *__pyx_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
  PyArrayObject *__pyx_v_img_ref = 0;
  PyArrayObject *__pyx_v_img_slice = 0;
  #if !CYTHON_METH_FASTCALL
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  #endif
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("calculate_slice_ccm (wrapper)", 0);
  #if !CYTHON_METH_FASTCALL
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args);
  if (unlikely((__pyx_nargs < 0))) __PYX_ERR(0, 93, __pyx_L3_error)
  #endif
  #endif
  __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
  {
    PyObject **__pyx_pyargnames[] = {&__pyx_n_s_img_ref,&__pyx_n_s_img_slice,0};
  PyObject* values[2] = {0,0};
    if (__pyx_kwds) {
      Py_ssize_t kw_args;
      switch (__pyx_nargs) {
        case  2: values[1] = __Pyx_Arg_FASTCALL(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = __Pyx_NumKwargs_FASTCALL(__pyx_kwds);
      switch (__pyx_nargs) {
        case  0:
        if (likely((values[0] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_img_ref)) != 0)) {
          (void)__Pyx_Arg_NewRef_FASTCALL(values[0]);
          kw_args--;
        }
        else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 93, __pyx_L3_error)
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_img_slice)) != 0)) {
          (void)__Pyx_Arg_NewRef_FASTCALL(values[1]);
          kw_args--;
        }
        else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 93, __pyx_L3_error)
        else {
          __Pyx_RaiseArgtupleInvalid("calculate_slice_ccm", 1, 2, 2, 1); __PYX_ERR(0, 93, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        const Py_ssize_t kwd_pos_args = __pyx_nargs;
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "calculate_slice_ccm") < 0)) __PYX_ERR(0, 93, __pyx_L3_error)
      }
    } else if (unlikely(__pyx_nargs != 2)) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
      values[1] = __Pyx_Arg_FASTCALL(__pyx_args, 1);
    }
    __pyx_v_img_ref = ((PyArrayObject *)values[0]);
    __pyx_v_img_slice = ((PyArrayObject *)values[1]);
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("calculate_slice_ccm", 1, 2, 2, __pyx_nargs); __PYX_ERR(0, 93, __pyx_L3_error)
  goto __pyx_L3_error;
  __pyx_L3_error:;
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_AddTraceback("nanopyx.core.analysis.ccm.calculate_slice_ccm", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_img_ref), __pyx_ptype_5numpy_ndarray, 1, "img_ref", 0))) __PYX_ERR(0, 93, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_img_slice), __pyx_ptype_5numpy_ndarray, 1, "img_slice", 0))) __PYX_ERR(0, 93, __pyx_L1_error)
  __pyx_r = __pyx_pf_7nanopyx_4core_8analysis_3ccm_4calculate_slice_ccm(__pyx_self, __pyx_v_img_ref, __pyx_v_img_slice);
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_7nanopyx_4core_8analysis_3ccm_4calculate_slice_ccm(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_img_ref, PyArrayObject *__pyx_v_img_slice) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_TraceFrameInit(__pyx_codeobj__13)
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("calculate_slice_ccm", 0);
  __Pyx_TraceCall("calculate_slice_ccm", __pyx_f[0], 93, 0, __PYX_ERR(0, 93, __pyx_L1_error));
/* … */
  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __PYX_XCLEAR_MEMVIEW(&__pyx_t_4, 1);
  __PYX_XCLEAR_MEMVIEW(&__pyx_t_5, 1);
  __PYX_XCLEAR_MEMVIEW(&__pyx_t_6, 1);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_AddTraceback("nanopyx.core.analysis.ccm.calculate_slice_ccm", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
/* … */
  __pyx_tuple__31 = PyTuple_Pack(2, __pyx_n_s_img_ref, __pyx_n_s_img_slice); if (unlikely(!__pyx_tuple__31)) __PYX_ERR(0, 93, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__31);
  __Pyx_GIVEREF(__pyx_tuple__31);
/* … */
  __pyx_t_7 = __Pyx_CyFunction_New(&__pyx_mdef_7nanopyx_4core_8analysis_3ccm_5calculate_slice_ccm, 0, __pyx_n_s_calculate_slice_ccm, NULL, __pyx_n_s_nanopyx_core_analysis_ccm, __pyx_d, ((PyObject *)__pyx_codeobj__13)); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 93, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_calculate_slice_ccm, __pyx_t_7) < 0) __PYX_ERR(0, 93, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_codeobj__13 = (PyObject*)__Pyx_PyCode_New(2, 0, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__31, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_nanopyx_core_analysis_ccm_py, __pyx_n_s_calculate_slice_ccm, 93, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__13)) __PYX_ERR(0, 93, __pyx_L1_error)
+094:     return np.array(_calculate_slice_ccm(img_ref, img_slice))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 94, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_array); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 94, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = __Pyx_PyObject_to_MemoryviewSlice_dsds_float(((PyObject *)__pyx_v_img_ref), PyBUF_WRITABLE); if (unlikely(!__pyx_t_4.memview)) __PYX_ERR(0, 94, __pyx_L1_error)
  __pyx_t_5 = __Pyx_PyObject_to_MemoryviewSlice_dsds_float(((PyObject *)__pyx_v_img_slice), PyBUF_WRITABLE); if (unlikely(!__pyx_t_5.memview)) __PYX_ERR(0, 94, __pyx_L1_error)
  __pyx_t_6 = __pyx_f_7nanopyx_4core_8analysis_3ccm__calculate_slice_ccm(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_6.memview)) __PYX_ERR(0, 94, __pyx_L1_error)
  __PYX_XCLEAR_MEMVIEW(&__pyx_t_4, 1);
  __pyx_t_4.memview = NULL; __pyx_t_4.data = NULL;
  __PYX_XCLEAR_MEMVIEW(&__pyx_t_5, 1);
  __pyx_t_5.memview = NULL; __pyx_t_5.data = NULL;
  __pyx_t_2 = __pyx_memoryview_fromslice(__pyx_t_6, 2, (PyObject *(*)(char *)) __pyx_memview_get_float, (int (*)(char *, PyObject *)) __pyx_memview_set_float, 0);; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 94, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __PYX_XCLEAR_MEMVIEW(&__pyx_t_6, 1);
  __pyx_t_6.memview = NULL; __pyx_t_6.data = NULL;
  __pyx_t_7 = NULL;
  __pyx_t_8 = 0;
  #if CYTHON_UNPACK_METHODS
  if (unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_7)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_7);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
      __pyx_t_8 = 1;
    }
  }
  #endif
  {
    PyObject *__pyx_callargs[2] = {__pyx_t_7, __pyx_t_2};
    __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_8, 1+__pyx_t_8);
    __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 94, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  }
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;
 095: 
+096: cdef void _normalize_ccm(float[:, :] img_ref, float[:, :] img_slice, float[:, :] ccm_slice) nogil:
static void __pyx_f_7nanopyx_4core_8analysis_3ccm__normalize_ccm(__Pyx_memviewslice __pyx_v_img_ref, __Pyx_memviewslice __pyx_v_img_slice, __Pyx_memviewslice __pyx_v_ccm_slice) {
  int __pyx_v_w;
  int __pyx_v_h;
  float __pyx_v_min_value;
  float __pyx_v_max_value;
  int __pyx_v_x_max;
  int __pyx_v_y_max;
  int __pyx_v_x_min;
  int __pyx_v_y_min;
  float __pyx_v_v;
  int __pyx_v_j;
  int __pyx_v_i;
  int __pyx_v_shift_x_max;
  int __pyx_v_shift_y_max;
  int __pyx_v_shift_x_min;
  int __pyx_v_shift_y_min;
  float __pyx_v_max_ppmcc;
  float __pyx_v_min_ppmcc;
  float __pyx_v_delta_v;
  float __pyx_v_value;
  float __pyx_v_delta_ppmcc;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_normalize_ccm", 1);
  __Pyx_TraceCall("_normalize_ccm", __pyx_f[0], 96, 1, __PYX_ERR(0, 96, __pyx_L1_error));
/* … */
  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  #ifdef WITH_THREAD
  __pyx_gilstate_save = __Pyx_PyGILState_Ensure();
  #endif
  __Pyx_AddTraceback("nanopyx.core.analysis.ccm._normalize_ccm", __pyx_clineno, __pyx_lineno, __pyx_filename);
  #ifdef WITH_THREAD
  __Pyx_PyGILState_Release(__pyx_gilstate_save);
  #endif
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 1);
  __Pyx_RefNannyFinishContextNogil()
}
 097:     """
 098:     Function used to normalize the cross correlation matrix.
 099: 
 100:     The code above does the following:
 101:     1. Find the maximum and minimum values of the cross-correlation matrix
 102:     2. Calculate the maximum and minimum PPMCC
 103:     3. Normalize the matrix values to the PPMCC values
 104:     """
 105: 
+106:     cdef int w = ccm_slice.shape[1]
  __pyx_v_w = (__pyx_v_ccm_slice.shape[1]);
+107:     cdef int h = ccm_slice.shape[0]
  __pyx_v_h = (__pyx_v_ccm_slice.shape[0]);
 108: 
+109:     cdef float min_value = ccm_slice[0, 0]
  __pyx_t_1 = 0;
  __pyx_t_2 = 0;
  __pyx_v_min_value = (*((float *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_ccm_slice.data + __pyx_t_1 * __pyx_v_ccm_slice.strides[0]) ) + __pyx_t_2 * __pyx_v_ccm_slice.strides[1]) )));
+110:     cdef float max_value = ccm_slice[0, 0]
  __pyx_t_2 = 0;
  __pyx_t_1 = 0;
  __pyx_v_max_value = (*((float *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_ccm_slice.data + __pyx_t_2 * __pyx_v_ccm_slice.strides[0]) ) + __pyx_t_1 * __pyx_v_ccm_slice.strides[1]) )));
+111:     cdef int x_max = 0
  __pyx_v_x_max = 0;
+112:     cdef int y_max = 0
  __pyx_v_y_max = 0;
+113:     cdef int x_min = 0
  __pyx_v_x_min = 0;
+114:     cdef int y_min = 0
  __pyx_v_y_min = 0;
 115:     cdef float v
 116: 
+117:     for j in range(h):
  __pyx_t_3 = __pyx_v_h;
  __pyx_t_4 = __pyx_t_3;
  for (__pyx_t_5 = 0; __pyx_t_5 < __pyx_t_4; __pyx_t_5+=1) {
    __pyx_v_j = __pyx_t_5;
+118:         for i in range(w):
    __pyx_t_6 = __pyx_v_w;
    __pyx_t_7 = __pyx_t_6;
    for (__pyx_t_8 = 0; __pyx_t_8 < __pyx_t_7; __pyx_t_8+=1) {
      __pyx_v_i = __pyx_t_8;
+119:             v = ccm_slice[j, i]
      __pyx_t_1 = __pyx_v_j;
      __pyx_t_2 = __pyx_v_i;
      __pyx_v_v = (*((float *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_ccm_slice.data + __pyx_t_1 * __pyx_v_ccm_slice.strides[0]) ) + __pyx_t_2 * __pyx_v_ccm_slice.strides[1]) )));
+120:             if v < min_value:
      __pyx_t_9 = (__pyx_v_v < __pyx_v_min_value);
      if (__pyx_t_9) {
/* … */
      }
+121:                 min_value = v
        __pyx_v_min_value = __pyx_v_v;
+122:                 x_min = i
        __pyx_v_x_min = __pyx_v_i;
+123:                 y_min = j
        __pyx_v_y_min = __pyx_v_j;
+124:             if v > max_value:
      __pyx_t_9 = (__pyx_v_v > __pyx_v_max_value);
      if (__pyx_t_9) {
/* … */
      }
    }
  }
+125:                 max_value = v
        __pyx_v_max_value = __pyx_v_v;
+126:                 x_max = i
        __pyx_v_x_max = __pyx_v_i;
+127:                 y_max = j
        __pyx_v_y_max = __pyx_v_j;
 128: 
+129:     cdef int shift_x_max = x_max - w // 2
  __pyx_v_shift_x_max = (__pyx_v_x_max - (__pyx_v_w / 2));
+130:     cdef int shift_y_max = y_max - h // 2
  __pyx_v_shift_y_max = (__pyx_v_y_max - (__pyx_v_h / 2));
+131:     cdef int shift_x_min = x_min - w // 2
  __pyx_v_shift_x_min = (__pyx_v_x_min - (__pyx_v_w / 2));
+132:     cdef int shift_y_min = y_min - h // 2
  __pyx_v_shift_y_min = (__pyx_v_y_min - (__pyx_v_h / 2));
 133: 
+134:     cdef float max_ppmcc = _calculate_ppmcc(img_ref, img_slice, shift_x_max, shift_y_max)
  __pyx_t_10 = __pyx_f_7nanopyx_4core_8analysis_19pearson_correlation__calculate_ppmcc(__pyx_v_img_ref, __pyx_v_img_slice, __pyx_v_shift_x_max, __pyx_v_shift_y_max); if (unlikely(__Pyx_ErrOccurredWithGIL())) __PYX_ERR(0, 134, __pyx_L1_error)
  __pyx_v_max_ppmcc = __pyx_t_10;
+135:     cdef float min_ppmcc = _calculate_ppmcc(img_ref, img_slice, shift_x_min, shift_y_min)
  __pyx_t_10 = __pyx_f_7nanopyx_4core_8analysis_19pearson_correlation__calculate_ppmcc(__pyx_v_img_ref, __pyx_v_img_slice, __pyx_v_shift_x_min, __pyx_v_shift_y_min); if (unlikely(__Pyx_ErrOccurredWithGIL())) __PYX_ERR(0, 135, __pyx_L1_error)
  __pyx_v_min_ppmcc = __pyx_t_10;
 136: 
+137:     cdef float delta_v = max_value - min_value
  __pyx_v_delta_v = (__pyx_v_max_value - __pyx_v_min_value);
 138:     cdef float value
+139:     cdef float delta_ppmcc = max_ppmcc - min_ppmcc
  __pyx_v_delta_ppmcc = (__pyx_v_max_ppmcc - __pyx_v_min_ppmcc);
 140: 
+141:     for j in range(h):
  __pyx_t_3 = __pyx_v_h;
  __pyx_t_4 = __pyx_t_3;
  for (__pyx_t_5 = 0; __pyx_t_5 < __pyx_t_4; __pyx_t_5+=1) {
    __pyx_v_j = __pyx_t_5;
+142:         for i in range(w):
    __pyx_t_6 = __pyx_v_w;
    __pyx_t_7 = __pyx_t_6;
    for (__pyx_t_8 = 0; __pyx_t_8 < __pyx_t_7; __pyx_t_8+=1) {
      __pyx_v_i = __pyx_t_8;
+143:             value = (ccm_slice[j, i] - min_value) / delta_v
      __pyx_t_2 = __pyx_v_j;
      __pyx_t_1 = __pyx_v_i;
      __pyx_v_value = (((*((float *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_ccm_slice.data + __pyx_t_2 * __pyx_v_ccm_slice.strides[0]) ) + __pyx_t_1 * __pyx_v_ccm_slice.strides[1]) ))) - __pyx_v_min_value) / __pyx_v_delta_v);
+144:             value = value * delta_ppmcc + min_ppmcc
      __pyx_v_value = ((__pyx_v_value * __pyx_v_delta_ppmcc) + __pyx_v_min_ppmcc);
+145:             ccm_slice[j, i] = value
      __pyx_t_1 = __pyx_v_j;
      __pyx_t_2 = __pyx_v_i;
      *((float *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_ccm_slice.data + __pyx_t_1 * __pyx_v_ccm_slice.strides[0]) ) + __pyx_t_2 * __pyx_v_ccm_slice.strides[1]) )) = __pyx_v_value;
    }
  }
 146: 
 147: 
+148: def calculate_rccm(np.ndarray img_slice, np.ndarray img_ref):
/* Python wrapper */
static PyObject *__pyx_pw_7nanopyx_4core_8analysis_3ccm_7calculate_rccm(PyObject *__pyx_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
PyDoc_STRVAR(__pyx_doc_7nanopyx_4core_8analysis_3ccm_6calculate_rccm, "\n    Function used to generate a rotational cross correlation matrix of an image against a reference image\n    Cross correlation values are normalized by the minimum and maximum Pearson's correlation between the two\n    images.\n    :param img_slice: numpy array with shape (y, x)\n    :param img_ref: numpy array with shape (y, x)\n    :return: numpy array with shape (360, y, x), corresponding to the rotational cross correlation matrix\n    ");
static PyMethodDef __pyx_mdef_7nanopyx_4core_8analysis_3ccm_7calculate_rccm = {"calculate_rccm", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_7nanopyx_4core_8analysis_3ccm_7calculate_rccm, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_7nanopyx_4core_8analysis_3ccm_6calculate_rccm};
static PyObject *__pyx_pw_7nanopyx_4core_8analysis_3ccm_7calculate_rccm(PyObject *__pyx_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
  PyArrayObject *__pyx_v_img_slice = 0;
  PyArrayObject *__pyx_v_img_ref = 0;
  #if !CYTHON_METH_FASTCALL
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  #endif
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("calculate_rccm (wrapper)", 0);
  #if !CYTHON_METH_FASTCALL
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args);
  if (unlikely((__pyx_nargs < 0))) __PYX_ERR(0, 148, __pyx_L3_error)
  #endif
  #endif
  __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
  {
    PyObject **__pyx_pyargnames[] = {&__pyx_n_s_img_slice,&__pyx_n_s_img_ref,0};
  PyObject* values[2] = {0,0};
    if (__pyx_kwds) {
      Py_ssize_t kw_args;
      switch (__pyx_nargs) {
        case  2: values[1] = __Pyx_Arg_FASTCALL(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = __Pyx_NumKwargs_FASTCALL(__pyx_kwds);
      switch (__pyx_nargs) {
        case  0:
        if (likely((values[0] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_img_slice)) != 0)) {
          (void)__Pyx_Arg_NewRef_FASTCALL(values[0]);
          kw_args--;
        }
        else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 148, __pyx_L3_error)
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_img_ref)) != 0)) {
          (void)__Pyx_Arg_NewRef_FASTCALL(values[1]);
          kw_args--;
        }
        else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 148, __pyx_L3_error)
        else {
          __Pyx_RaiseArgtupleInvalid("calculate_rccm", 1, 2, 2, 1); __PYX_ERR(0, 148, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        const Py_ssize_t kwd_pos_args = __pyx_nargs;
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "calculate_rccm") < 0)) __PYX_ERR(0, 148, __pyx_L3_error)
      }
    } else if (unlikely(__pyx_nargs != 2)) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
      values[1] = __Pyx_Arg_FASTCALL(__pyx_args, 1);
    }
    __pyx_v_img_slice = ((PyArrayObject *)values[0]);
    __pyx_v_img_ref = ((PyArrayObject *)values[1]);
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("calculate_rccm", 1, 2, 2, __pyx_nargs); __PYX_ERR(0, 148, __pyx_L3_error)
  goto __pyx_L3_error;
  __pyx_L3_error:;
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_AddTraceback("nanopyx.core.analysis.ccm.calculate_rccm", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_img_slice), __pyx_ptype_5numpy_ndarray, 1, "img_slice", 0))) __PYX_ERR(0, 148, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_img_ref), __pyx_ptype_5numpy_ndarray, 1, "img_ref", 0))) __PYX_ERR(0, 148, __pyx_L1_error)
  __pyx_r = __pyx_pf_7nanopyx_4core_8analysis_3ccm_6calculate_rccm(__pyx_self, __pyx_v_img_slice, __pyx_v_img_ref);
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_7nanopyx_4core_8analysis_3ccm_6calculate_rccm(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_img_slice, PyArrayObject *__pyx_v_img_ref) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_TraceFrameInit(__pyx_codeobj__14)
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("calculate_rccm", 0);
  __Pyx_TraceCall("calculate_rccm", __pyx_f[0], 148, 0, __PYX_ERR(0, 148, __pyx_L1_error));
/* … */
  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __PYX_XCLEAR_MEMVIEW(&__pyx_t_4, 1);
  __PYX_XCLEAR_MEMVIEW(&__pyx_t_5, 1);
  __PYX_XCLEAR_MEMVIEW(&__pyx_t_6, 1);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_AddTraceback("nanopyx.core.analysis.ccm.calculate_rccm", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
/* … */
  __pyx_tuple__32 = PyTuple_Pack(2, __pyx_n_s_img_slice, __pyx_n_s_img_ref); if (unlikely(!__pyx_tuple__32)) __PYX_ERR(0, 148, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__32);
  __Pyx_GIVEREF(__pyx_tuple__32);
/* … */
  __pyx_t_7 = __Pyx_CyFunction_New(&__pyx_mdef_7nanopyx_4core_8analysis_3ccm_7calculate_rccm, 0, __pyx_n_s_calculate_rccm, NULL, __pyx_n_s_nanopyx_core_analysis_ccm, __pyx_d, ((PyObject *)__pyx_codeobj__14)); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 148, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_calculate_rccm, __pyx_t_7) < 0) __PYX_ERR(0, 148, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_codeobj__14 = (PyObject*)__Pyx_PyCode_New(2, 0, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__32, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_nanopyx_core_analysis_ccm_py, __pyx_n_s_calculate_rccm, 148, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__14)) __PYX_ERR(0, 148, __pyx_L1_error)
 149:     """
 150:     Function used to generate a rotational cross correlation matrix of an image against a reference image
 151:     Cross correlation values are normalized by the minimum and maximum Pearson's correlation between the two
 152:     images.
 153:     :param img_slice: numpy array with shape (y, x)
 154:     :param img_ref: numpy array with shape (y, x)
 155:     :return: numpy array with shape (360, y, x), corresponding to the rotational cross correlation matrix
 156:     """
+157:     return np.array(_calculate_rccm(img_slice, img_ref))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 157, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_array); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 157, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = __Pyx_PyObject_to_MemoryviewSlice_dsds_float(((PyObject *)__pyx_v_img_slice), PyBUF_WRITABLE); if (unlikely(!__pyx_t_4.memview)) __PYX_ERR(0, 157, __pyx_L1_error)
  __pyx_t_5 = __Pyx_PyObject_to_MemoryviewSlice_dsds_float(((PyObject *)__pyx_v_img_ref), PyBUF_WRITABLE); if (unlikely(!__pyx_t_5.memview)) __PYX_ERR(0, 157, __pyx_L1_error)
  __pyx_t_6 = __pyx_f_7nanopyx_4core_8analysis_3ccm__calculate_rccm(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_6.memview)) __PYX_ERR(0, 157, __pyx_L1_error)
  __PYX_XCLEAR_MEMVIEW(&__pyx_t_4, 1);
  __pyx_t_4.memview = NULL; __pyx_t_4.data = NULL;
  __PYX_XCLEAR_MEMVIEW(&__pyx_t_5, 1);
  __pyx_t_5.memview = NULL; __pyx_t_5.data = NULL;
  __pyx_t_2 = __pyx_memoryview_fromslice(__pyx_t_6, 3, (PyObject *(*)(char *)) __pyx_memview_get_float, (int (*)(char *, PyObject *)) __pyx_memview_set_float, 0);; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 157, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __PYX_XCLEAR_MEMVIEW(&__pyx_t_6, 1);
  __pyx_t_6.memview = NULL; __pyx_t_6.data = NULL;
  __pyx_t_7 = NULL;
  __pyx_t_8 = 0;
  #if CYTHON_UNPACK_METHODS
  if (unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_7)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_7);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
      __pyx_t_8 = 1;
    }
  }
  #endif
  {
    PyObject *__pyx_callargs[2] = {__pyx_t_7, __pyx_t_2};
    __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_8, 1+__pyx_t_8);
    __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 157, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  }
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;
 158: 
+159: cdef float[:,:,:] _calculate_rccm(float[:, :] img_slice, float[:, :] img_ref):
static __Pyx_memviewslice __pyx_f_7nanopyx_4core_8analysis_3ccm__calculate_rccm(__Pyx_memviewslice __pyx_v_img_slice, __Pyx_memviewslice __pyx_v_img_ref) {
  __Pyx_memviewslice __pyx_v_tmp = { 0, 0, { 0 }, { 0 }, { 0 } };
  int __pyx_v_height;
  int __pyx_v_width;
  __Pyx_memviewslice __pyx_v_rccm = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_rotated_img_slice = { 0, 0, { 0 }, { 0 }, { 0 } };
  int __pyx_v_degree;
  float __pyx_v_radian;
  __Pyx_memviewslice __pyx_r = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_calculate_rccm", 0);
  __Pyx_TraceCall("_calculate_rccm", __pyx_f[0], 159, 0, __PYX_ERR(0, 159, __pyx_L1_error));
  __PYX_INC_MEMVIEW(&__pyx_v_img_slice, 1);
  __PYX_INC_MEMVIEW(&__pyx_v_img_ref, 1);
/* … */
  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __PYX_XCLEAR_MEMVIEW(&__pyx_t_6, 1);
  __PYX_XCLEAR_MEMVIEW(&__pyx_t_9, 1);
  __Pyx_XDECREF(__pyx_t_10);
  __PYX_XCLEAR_MEMVIEW(&__pyx_t_12, 1);
  __pyx_r.data = NULL;
  __pyx_r.memview = NULL;
  __Pyx_AddTraceback("nanopyx.core.analysis.ccm._calculate_rccm", __pyx_clineno, __pyx_lineno, __pyx_filename);
  goto __pyx_L2;
  __pyx_L0:;
  if (unlikely(!__pyx_r.memview)) {
    PyErr_SetString(PyExc_TypeError, "Memoryview return value is not initialized");
  }
  __pyx_L2:;
  __PYX_XCLEAR_MEMVIEW(&__pyx_v_tmp, 1);
  __PYX_XCLEAR_MEMVIEW(&__pyx_v_rccm, 1);
  __PYX_XCLEAR_MEMVIEW(&__pyx_v_rotated_img_slice, 1);
  __PYX_XCLEAR_MEMVIEW(&__pyx_v_img_slice, 1);
  __PYX_XCLEAR_MEMVIEW(&__pyx_v_img_ref, 1);
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
 160: 
 161:     cdef float[:,:,:] tmp
 162: 
+163:     tmp = np.array([img_slice])
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 163, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_array); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 163, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __pyx_memoryview_fromslice(__pyx_v_img_slice, 2, (PyObject *(*)(char *)) __pyx_memview_get_float, (int (*)(char *, PyObject *)) __pyx_memview_set_float, 0);; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 163, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = PyList_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 163, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_2);
  if (__Pyx_PyList_SET_ITEM(__pyx_t_4, 0, __pyx_t_2)) __PYX_ERR(0, 163, __pyx_L1_error);
  __pyx_t_2 = 0;
  __pyx_t_2 = NULL;
  __pyx_t_5 = 0;
  #if CYTHON_UNPACK_METHODS
  if (unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
      __pyx_t_5 = 1;
    }
  }
  #endif
  {
    PyObject *__pyx_callargs[2] = {__pyx_t_2, __pyx_t_4};
    __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_5, 1+__pyx_t_5);
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 163, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  }
  __pyx_t_6 = __Pyx_PyObject_to_MemoryviewSlice_dsdsds_float(__pyx_t_1, PyBUF_WRITABLE); if (unlikely(!__pyx_t_6.memview)) __PYX_ERR(0, 163, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_tmp = __pyx_t_6;
  __pyx_t_6.memview = NULL;
  __pyx_t_6.data = NULL;
+164:     if not _check_even_square(tmp):
  __pyx_t_7 = __pyx_f_7nanopyx_4core_8analysis_20ccm_helper_functions__check_even_square(__pyx_v_tmp); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 164, __pyx_L1_error)
  __pyx_t_8 = (!__pyx_t_7);
  if (__pyx_t_8) {
/* … */
  }
+165:         tmp = _make_even_square(tmp)
    __pyx_t_6 = __pyx_f_7nanopyx_4core_8analysis_20ccm_helper_functions__make_even_square(__pyx_v_tmp); if (unlikely(!__pyx_t_6.memview)) __PYX_ERR(0, 165, __pyx_L1_error)
    __PYX_XCLEAR_MEMVIEW(&__pyx_v_tmp, 1);
    __pyx_v_tmp = __pyx_t_6;
    __pyx_t_6.memview = NULL;
    __pyx_t_6.data = NULL;
+166:         img_slice = tmp[0]
    __pyx_t_9.data = __pyx_v_tmp.data;
    __pyx_t_9.memview = __pyx_v_tmp.memview;
    __PYX_INC_MEMVIEW(&__pyx_t_9, 1);
    {
    Py_ssize_t __pyx_tmp_idx = 0;
    Py_ssize_t __pyx_tmp_stride = __pyx_v_tmp.strides[0];
        __pyx_t_9.data += __pyx_tmp_idx * __pyx_tmp_stride;
}

__pyx_t_9.shape[0] = __pyx_v_tmp.shape[1];
__pyx_t_9.strides[0] = __pyx_v_tmp.strides[1];
    __pyx_t_9.suboffsets[0] = -1;

__pyx_t_9.shape[1] = __pyx_v_tmp.shape[2];
__pyx_t_9.strides[1] = __pyx_v_tmp.strides[2];
    __pyx_t_9.suboffsets[1] = -1;

__PYX_XCLEAR_MEMVIEW(&__pyx_v_img_slice, 1);
    __pyx_v_img_slice = __pyx_t_9;
    __pyx_t_9.memview = NULL;
    __pyx_t_9.data = NULL;
 167: 
+168:     tmp = np.array([img_ref])
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 168, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_array); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 168, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __pyx_memoryview_fromslice(__pyx_v_img_ref, 2, (PyObject *(*)(char *)) __pyx_memview_get_float, (int (*)(char *, PyObject *)) __pyx_memview_set_float, 0);; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 168, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 168, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_3);
  if (__Pyx_PyList_SET_ITEM(__pyx_t_2, 0, __pyx_t_3)) __PYX_ERR(0, 168, __pyx_L1_error);
  __pyx_t_3 = 0;
  __pyx_t_3 = NULL;
  __pyx_t_5 = 0;
  #if CYTHON_UNPACK_METHODS
  if (unlikely(PyMethod_Check(__pyx_t_4))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_4, function);
      __pyx_t_5 = 1;
    }
  }
  #endif
  {
    PyObject *__pyx_callargs[2] = {__pyx_t_3, __pyx_t_2};
    __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_4, __pyx_callargs+1-__pyx_t_5, 1+__pyx_t_5);
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 168, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  }
  __pyx_t_6 = __Pyx_PyObject_to_MemoryviewSlice_dsdsds_float(__pyx_t_1, PyBUF_WRITABLE); if (unlikely(!__pyx_t_6.memview)) __PYX_ERR(0, 168, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __PYX_XCLEAR_MEMVIEW(&__pyx_v_tmp, 1);
  __pyx_v_tmp = __pyx_t_6;
  __pyx_t_6.memview = NULL;
  __pyx_t_6.data = NULL;
+169:     if not _check_even_square(tmp):
  __pyx_t_8 = __pyx_f_7nanopyx_4core_8analysis_20ccm_helper_functions__check_even_square(__pyx_v_tmp); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 169, __pyx_L1_error)
  __pyx_t_7 = (!__pyx_t_8);
  if (__pyx_t_7) {
/* … */
  }
+170:         tmp = _make_even_square(tmp)
    __pyx_t_6 = __pyx_f_7nanopyx_4core_8analysis_20ccm_helper_functions__make_even_square(__pyx_v_tmp); if (unlikely(!__pyx_t_6.memview)) __PYX_ERR(0, 170, __pyx_L1_error)
    __PYX_XCLEAR_MEMVIEW(&__pyx_v_tmp, 1);
    __pyx_v_tmp = __pyx_t_6;
    __pyx_t_6.memview = NULL;
    __pyx_t_6.data = NULL;
+171:         img_ref = tmp[0]
    __pyx_t_9.data = __pyx_v_tmp.data;
    __pyx_t_9.memview = __pyx_v_tmp.memview;
    __PYX_INC_MEMVIEW(&__pyx_t_9, 1);
    {
    Py_ssize_t __pyx_tmp_idx = 0;
    Py_ssize_t __pyx_tmp_stride = __pyx_v_tmp.strides[0];
        __pyx_t_9.data += __pyx_tmp_idx * __pyx_tmp_stride;
}

__pyx_t_9.shape[0] = __pyx_v_tmp.shape[1];
__pyx_t_9.strides[0] = __pyx_v_tmp.strides[1];
    __pyx_t_9.suboffsets[0] = -1;

__pyx_t_9.shape[1] = __pyx_v_tmp.shape[2];
__pyx_t_9.strides[1] = __pyx_v_tmp.strides[2];
    __pyx_t_9.suboffsets[1] = -1;

__PYX_XCLEAR_MEMVIEW(&__pyx_v_img_ref, 1);
    __pyx_v_img_ref = __pyx_t_9;
    __pyx_t_9.memview = NULL;
    __pyx_t_9.data = NULL;
 172: 
+173:     cdef int height = img_slice.shape[0]
  __pyx_v_height = (__pyx_v_img_slice.shape[0]);
+174:     cdef int width = img_slice.shape[1]
  __pyx_v_width = (__pyx_v_img_slice.shape[1]);
 175: 
+176:     cdef float[:,:,:] rccm = np.empty((360,height,width), dtype=np.float32)
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 176, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_empty); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 176, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_height); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 176, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_width); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 176, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 176, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(__pyx_int_360);
  __Pyx_GIVEREF(__pyx_int_360);
  if (__Pyx_PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_int_360)) __PYX_ERR(0, 176, __pyx_L1_error);
  __Pyx_GIVEREF(__pyx_t_1);
  if (__Pyx_PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_1)) __PYX_ERR(0, 176, __pyx_L1_error);
  __Pyx_GIVEREF(__pyx_t_2);
  if (__Pyx_PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_t_2)) __PYX_ERR(0, 176, __pyx_L1_error);
  __pyx_t_1 = 0;
  __pyx_t_2 = 0;
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 176, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_3);
  if (__Pyx_PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3)) __PYX_ERR(0, 176, __pyx_L1_error);
  __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 176, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 176, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_float32); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 176, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_10);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_dtype, __pyx_t_10) < 0) __PYX_ERR(0, 176, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
  __pyx_t_10 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 176, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_10);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_6 = __Pyx_PyObject_to_MemoryviewSlice_dsdsds_float(__pyx_t_10, PyBUF_WRITABLE); if (unlikely(!__pyx_t_6.memview)) __PYX_ERR(0, 176, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
  __pyx_v_rccm = __pyx_t_6;
  __pyx_t_6.memview = NULL;
  __pyx_t_6.data = NULL;
 177: 
 178:     cdef float[:,:] rotated_img_slice
 179: 
 180:     cdef int degree
 181:     cdef float radian
+182:     for degree in range(360):
  for (__pyx_t_5 = 0; __pyx_t_5 < 0x168; __pyx_t_5+=1) {
    __pyx_v_degree = __pyx_t_5;
+183:         radian = degree * pi/180
    __pyx_v_radian = ((__pyx_v_degree * M_PI) / 180.0);
+184:         rotated_img_slice = Interpolator(img_slice).rotate(radian)
    __pyx_t_3 = __pyx_memoryview_fromslice(__pyx_v_img_slice, 2, (PyObject *(*)(char *)) __pyx_memview_get_float, (int (*)(char *, PyObject *)) __pyx_memview_set_float, 0);; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 184, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = __Pyx_PyObject_CallOneArg(((PyObject *)__pyx_ptype_7nanopyx_4core_9transform_25interpolation_catmull_rom_Interpolator), __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 184, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_rotate); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 184, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = PyFloat_FromDouble(__pyx_v_radian); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 184, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_4 = NULL;
    __pyx_t_11 = 0;
    #if CYTHON_UNPACK_METHODS
    if (likely(PyMethod_Check(__pyx_t_3))) {
      __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
      if (likely(__pyx_t_4)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_4);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_3, function);
        __pyx_t_11 = 1;
      }
    }
    #endif
    {
      PyObject *__pyx_callargs[2] = {__pyx_t_4, __pyx_t_2};
      __pyx_t_10 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_11, 1+__pyx_t_11);
      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 184, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_10);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    }
    __pyx_t_9 = __Pyx_PyObject_to_MemoryviewSlice_dsds_float(__pyx_t_10, PyBUF_WRITABLE); if (unlikely(!__pyx_t_9.memview)) __PYX_ERR(0, 184, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
    __PYX_XCLEAR_MEMVIEW(&__pyx_v_rotated_img_slice, 1);
    __pyx_v_rotated_img_slice = __pyx_t_9;
    __pyx_t_9.memview = NULL;
    __pyx_t_9.data = NULL;
+185:         rccm[degree] = _calculate_slice_ccm(img_ref, rotated_img_slice)
    __pyx_t_9 = __pyx_f_7nanopyx_4core_8analysis_3ccm__calculate_slice_ccm(__pyx_v_img_ref, __pyx_v_rotated_img_slice); if (unlikely(!__pyx_t_9.memview)) __PYX_ERR(0, 185, __pyx_L1_error)
    __pyx_t_12.data = __pyx_v_rccm.data;
    __pyx_t_12.memview = __pyx_v_rccm.memview;
    __PYX_INC_MEMVIEW(&__pyx_t_12, 1);
    {
    Py_ssize_t __pyx_tmp_idx = __pyx_v_degree;
    Py_ssize_t __pyx_tmp_stride = __pyx_v_rccm.strides[0];
        __pyx_t_12.data += __pyx_tmp_idx * __pyx_tmp_stride;
}

__pyx_t_12.shape[0] = __pyx_v_rccm.shape[1];
__pyx_t_12.strides[0] = __pyx_v_rccm.strides[1];
    __pyx_t_12.suboffsets[0] = -1;

__pyx_t_12.shape[1] = __pyx_v_rccm.shape[2];
__pyx_t_12.strides[1] = __pyx_v_rccm.strides[2];
    __pyx_t_12.suboffsets[1] = -1;

if (unlikely((__pyx_memoryview_copy_contents(__pyx_t_9, __pyx_t_12, 2, 2, 0) < 0))) __PYX_ERR(0, 185, __pyx_L1_error)
    __PYX_XCLEAR_MEMVIEW(&__pyx_t_12, 1);
    __pyx_t_12.memview = NULL; __pyx_t_12.data = NULL;
    __PYX_XCLEAR_MEMVIEW(&__pyx_t_9, 1);
    __pyx_t_9.memview = NULL; __pyx_t_9.data = NULL;
  }
 186: 
+187:     return rccm
  __PYX_INC_MEMVIEW(&__pyx_v_rccm, 1);
  __pyx_r = __pyx_v_rccm;
  goto __pyx_L0;
 188: 
+189: def calculate_ccm_cartesian(np.ndarray img_slice, np.ndarray img_ref): # TODO DEPRECATED?
/* Python wrapper */
static PyObject *__pyx_pw_7nanopyx_4core_8analysis_3ccm_9calculate_ccm_cartesian(PyObject *__pyx_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
PyDoc_STRVAR(__pyx_doc_7nanopyx_4core_8analysis_3ccm_8calculate_ccm_cartesian, "\n    Function used to generate a cross correlation matrix of an image against a reference image\n    Cross correlation values are normalized by the minimum and maximum Pearson's correlation between the two polar images.\n    :param img_slice: numpy array with shape (y, x)\n    :param img_ref: numpy array with shape (y, x)\n    :return: numpy array with shape (y,x), corresponding to the cross correlation matrix\n    ");
static PyMethodDef __pyx_mdef_7nanopyx_4core_8analysis_3ccm_9calculate_ccm_cartesian = {"calculate_ccm_cartesian", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_7nanopyx_4core_8analysis_3ccm_9calculate_ccm_cartesian, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_7nanopyx_4core_8analysis_3ccm_8calculate_ccm_cartesian};
static PyObject *__pyx_pw_7nanopyx_4core_8analysis_3ccm_9calculate_ccm_cartesian(PyObject *__pyx_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
  PyArrayObject *__pyx_v_img_slice = 0;
  PyArrayObject *__pyx_v_img_ref = 0;
  #if !CYTHON_METH_FASTCALL
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  #endif
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("calculate_ccm_cartesian (wrapper)", 0);
  #if !CYTHON_METH_FASTCALL
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args);
  if (unlikely((__pyx_nargs < 0))) __PYX_ERR(0, 189, __pyx_L3_error)
  #endif
  #endif
  __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
  {
    PyObject **__pyx_pyargnames[] = {&__pyx_n_s_img_slice,&__pyx_n_s_img_ref,0};
  PyObject* values[2] = {0,0};
    if (__pyx_kwds) {
      Py_ssize_t kw_args;
      switch (__pyx_nargs) {
        case  2: values[1] = __Pyx_Arg_FASTCALL(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = __Pyx_NumKwargs_FASTCALL(__pyx_kwds);
      switch (__pyx_nargs) {
        case  0:
        if (likely((values[0] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_img_slice)) != 0)) {
          (void)__Pyx_Arg_NewRef_FASTCALL(values[0]);
          kw_args--;
        }
        else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 189, __pyx_L3_error)
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_img_ref)) != 0)) {
          (void)__Pyx_Arg_NewRef_FASTCALL(values[1]);
          kw_args--;
        }
        else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 189, __pyx_L3_error)
        else {
          __Pyx_RaiseArgtupleInvalid("calculate_ccm_cartesian", 1, 2, 2, 1); __PYX_ERR(0, 189, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        const Py_ssize_t kwd_pos_args = __pyx_nargs;
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "calculate_ccm_cartesian") < 0)) __PYX_ERR(0, 189, __pyx_L3_error)
      }
    } else if (unlikely(__pyx_nargs != 2)) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
      values[1] = __Pyx_Arg_FASTCALL(__pyx_args, 1);
    }
    __pyx_v_img_slice = ((PyArrayObject *)values[0]);
    __pyx_v_img_ref = ((PyArrayObject *)values[1]);
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("calculate_ccm_cartesian", 1, 2, 2, __pyx_nargs); __PYX_ERR(0, 189, __pyx_L3_error)
  goto __pyx_L3_error;
  __pyx_L3_error:;
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_AddTraceback("nanopyx.core.analysis.ccm.calculate_ccm_cartesian", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_img_slice), __pyx_ptype_5numpy_ndarray, 1, "img_slice", 0))) __PYX_ERR(0, 189, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_img_ref), __pyx_ptype_5numpy_ndarray, 1, "img_ref", 0))) __PYX_ERR(0, 189, __pyx_L1_error)
  __pyx_r = __pyx_pf_7nanopyx_4core_8analysis_3ccm_8calculate_ccm_cartesian(__pyx_self, __pyx_v_img_slice, __pyx_v_img_ref);
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_7nanopyx_4core_8analysis_3ccm_8calculate_ccm_cartesian(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_img_slice, PyArrayObject *__pyx_v_img_ref) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_TraceFrameInit(__pyx_codeobj__15)
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("calculate_ccm_cartesian", 0);
  __Pyx_TraceCall("calculate_ccm_cartesian", __pyx_f[0], 189, 0, __PYX_ERR(0, 189, __pyx_L1_error));
/* … */
  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __PYX_XCLEAR_MEMVIEW(&__pyx_t_4, 1);
  __PYX_XCLEAR_MEMVIEW(&__pyx_t_5, 1);
  __PYX_XCLEAR_MEMVIEW(&__pyx_t_6, 1);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_AddTraceback("nanopyx.core.analysis.ccm.calculate_ccm_cartesian", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
/* … */
  __pyx_t_7 = __Pyx_CyFunction_New(&__pyx_mdef_7nanopyx_4core_8analysis_3ccm_9calculate_ccm_cartesian, 0, __pyx_n_s_calculate_ccm_cartesian, NULL, __pyx_n_s_nanopyx_core_analysis_ccm, __pyx_d, ((PyObject *)__pyx_codeobj__15)); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 189, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_calculate_ccm_cartesian, __pyx_t_7) < 0) __PYX_ERR(0, 189, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
/* … */
  __pyx_codeobj__15 = (PyObject*)__Pyx_PyCode_New(2, 0, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__32, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_nanopyx_core_analysis_ccm_py, __pyx_n_s_calculate_ccm_cartesian, 189, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__15)) __PYX_ERR(0, 189, __pyx_L1_error)
 190:     """
 191:     Function used to generate a cross correlation matrix of an image against a reference image
 192:     Cross correlation values are normalized by the minimum and maximum Pearson's correlation between the two polar images.
 193:     :param img_slice: numpy array with shape (y, x)
 194:     :param img_ref: numpy array with shape (y, x)
 195:     :return: numpy array with shape (y,x), corresponding to the cross correlation matrix
 196:     """
+197:     return np.array(_calculate_ccm_cartesian(img_slice, img_ref))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 197, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_array); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 197, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = __Pyx_PyObject_to_MemoryviewSlice_dsds_float(((PyObject *)__pyx_v_img_slice), PyBUF_WRITABLE); if (unlikely(!__pyx_t_4.memview)) __PYX_ERR(0, 197, __pyx_L1_error)
  __pyx_t_5 = __Pyx_PyObject_to_MemoryviewSlice_dsds_float(((PyObject *)__pyx_v_img_ref), PyBUF_WRITABLE); if (unlikely(!__pyx_t_5.memview)) __PYX_ERR(0, 197, __pyx_L1_error)
  __pyx_t_6 = __pyx_f_7nanopyx_4core_8analysis_3ccm__calculate_ccm_cartesian(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_6.memview)) __PYX_ERR(0, 197, __pyx_L1_error)
  __PYX_XCLEAR_MEMVIEW(&__pyx_t_4, 1);
  __pyx_t_4.memview = NULL; __pyx_t_4.data = NULL;
  __PYX_XCLEAR_MEMVIEW(&__pyx_t_5, 1);
  __pyx_t_5.memview = NULL; __pyx_t_5.data = NULL;
  __pyx_t_2 = __pyx_memoryview_fromslice(__pyx_t_6, 2, (PyObject *(*)(char *)) __pyx_memview_get_float, (int (*)(char *, PyObject *)) __pyx_memview_set_float, 0);; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 197, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __PYX_XCLEAR_MEMVIEW(&__pyx_t_6, 1);
  __pyx_t_6.memview = NULL; __pyx_t_6.data = NULL;
  __pyx_t_7 = NULL;
  __pyx_t_8 = 0;
  #if CYTHON_UNPACK_METHODS
  if (unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_7)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_7);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
      __pyx_t_8 = 1;
    }
  }
  #endif
  {
    PyObject *__pyx_callargs[2] = {__pyx_t_7, __pyx_t_2};
    __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_8, 1+__pyx_t_8);
    __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 197, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  }
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;
 198: 
+199: cdef float[:,:] _calculate_ccm_cartesian(float[:, :] img_slice, float[:, :] img_ref): # TODO DEPRECATED?
static __Pyx_memviewslice __pyx_f_7nanopyx_4core_8analysis_3ccm__calculate_ccm_cartesian(__Pyx_memviewslice __pyx_v_img_slice, __Pyx_memviewslice __pyx_v_img_ref) {
  __Pyx_memviewslice __pyx_v_tmp = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_r = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_calculate_ccm_cartesian", 0);
  __Pyx_TraceCall("_calculate_ccm_cartesian", __pyx_f[0], 199, 0, __PYX_ERR(0, 199, __pyx_L1_error));
  __PYX_INC_MEMVIEW(&__pyx_v_img_slice, 1);
  __PYX_INC_MEMVIEW(&__pyx_v_img_ref, 1);
/* … */
  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __PYX_XCLEAR_MEMVIEW(&__pyx_t_6, 1);
  __PYX_XCLEAR_MEMVIEW(&__pyx_t_9, 1);
  __pyx_r.data = NULL;
  __pyx_r.memview = NULL;
  __Pyx_AddTraceback("nanopyx.core.analysis.ccm._calculate_ccm_cartesian", __pyx_clineno, __pyx_lineno, __pyx_filename);
  goto __pyx_L2;
  __pyx_L0:;
  if (unlikely(!__pyx_r.memview)) {
    PyErr_SetString(PyExc_TypeError, "Memoryview return value is not initialized");
  }
  __pyx_L2:;
  __PYX_XCLEAR_MEMVIEW(&__pyx_v_tmp, 1);
  __PYX_XCLEAR_MEMVIEW(&__pyx_v_img_slice, 1);
  __PYX_XCLEAR_MEMVIEW(&__pyx_v_img_ref, 1);
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
 200: 
 201:     cdef float[:,:,:] tmp
 202: 
+203:     tmp = np.array([img_slice])
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 203, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_array); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 203, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __pyx_memoryview_fromslice(__pyx_v_img_slice, 2, (PyObject *(*)(char *)) __pyx_memview_get_float, (int (*)(char *, PyObject *)) __pyx_memview_set_float, 0);; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 203, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = PyList_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 203, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_2);
  if (__Pyx_PyList_SET_ITEM(__pyx_t_4, 0, __pyx_t_2)) __PYX_ERR(0, 203, __pyx_L1_error);
  __pyx_t_2 = 0;
  __pyx_t_2 = NULL;
  __pyx_t_5 = 0;
  #if CYTHON_UNPACK_METHODS
  if (unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
      __pyx_t_5 = 1;
    }
  }
  #endif
  {
    PyObject *__pyx_callargs[2] = {__pyx_t_2, __pyx_t_4};
    __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_5, 1+__pyx_t_5);
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 203, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  }
  __pyx_t_6 = __Pyx_PyObject_to_MemoryviewSlice_dsdsds_float(__pyx_t_1, PyBUF_WRITABLE); if (unlikely(!__pyx_t_6.memview)) __PYX_ERR(0, 203, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_tmp = __pyx_t_6;
  __pyx_t_6.memview = NULL;
  __pyx_t_6.data = NULL;
+204:     if not _check_even_square(tmp):
  __pyx_t_7 = __pyx_f_7nanopyx_4core_8analysis_20ccm_helper_functions__check_even_square(__pyx_v_tmp); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 204, __pyx_L1_error)
  __pyx_t_8 = (!__pyx_t_7);
  if (__pyx_t_8) {
/* … */
  }
+205:         tmp = _make_even_square(tmp)
    __pyx_t_6 = __pyx_f_7nanopyx_4core_8analysis_20ccm_helper_functions__make_even_square(__pyx_v_tmp); if (unlikely(!__pyx_t_6.memview)) __PYX_ERR(0, 205, __pyx_L1_error)
    __PYX_XCLEAR_MEMVIEW(&__pyx_v_tmp, 1);
    __pyx_v_tmp = __pyx_t_6;
    __pyx_t_6.memview = NULL;
    __pyx_t_6.data = NULL;
+206:         img_slice = tmp[0]
    __pyx_t_9.data = __pyx_v_tmp.data;
    __pyx_t_9.memview = __pyx_v_tmp.memview;
    __PYX_INC_MEMVIEW(&__pyx_t_9, 1);
    {
    Py_ssize_t __pyx_tmp_idx = 0;
    Py_ssize_t __pyx_tmp_stride = __pyx_v_tmp.strides[0];
        __pyx_t_9.data += __pyx_tmp_idx * __pyx_tmp_stride;
}

__pyx_t_9.shape[0] = __pyx_v_tmp.shape[1];
__pyx_t_9.strides[0] = __pyx_v_tmp.strides[1];
    __pyx_t_9.suboffsets[0] = -1;

__pyx_t_9.shape[1] = __pyx_v_tmp.shape[2];
__pyx_t_9.strides[1] = __pyx_v_tmp.strides[2];
    __pyx_t_9.suboffsets[1] = -1;

__PYX_XCLEAR_MEMVIEW(&__pyx_v_img_slice, 1);
    __pyx_v_img_slice = __pyx_t_9;
    __pyx_t_9.memview = NULL;
    __pyx_t_9.data = NULL;
 207: 
+208:     tmp = np.array([img_ref])
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 208, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_array); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 208, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __pyx_memoryview_fromslice(__pyx_v_img_ref, 2, (PyObject *(*)(char *)) __pyx_memview_get_float, (int (*)(char *, PyObject *)) __pyx_memview_set_float, 0);; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 208, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 208, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_3);
  if (__Pyx_PyList_SET_ITEM(__pyx_t_2, 0, __pyx_t_3)) __PYX_ERR(0, 208, __pyx_L1_error);
  __pyx_t_3 = 0;
  __pyx_t_3 = NULL;
  __pyx_t_5 = 0;
  #if CYTHON_UNPACK_METHODS
  if (unlikely(PyMethod_Check(__pyx_t_4))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_4, function);
      __pyx_t_5 = 1;
    }
  }
  #endif
  {
    PyObject *__pyx_callargs[2] = {__pyx_t_3, __pyx_t_2};
    __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_4, __pyx_callargs+1-__pyx_t_5, 1+__pyx_t_5);
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 208, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  }
  __pyx_t_6 = __Pyx_PyObject_to_MemoryviewSlice_dsdsds_float(__pyx_t_1, PyBUF_WRITABLE); if (unlikely(!__pyx_t_6.memview)) __PYX_ERR(0, 208, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __PYX_XCLEAR_MEMVIEW(&__pyx_v_tmp, 1);
  __pyx_v_tmp = __pyx_t_6;
  __pyx_t_6.memview = NULL;
  __pyx_t_6.data = NULL;
+209:     if not _check_even_square(tmp):
  __pyx_t_8 = __pyx_f_7nanopyx_4core_8analysis_20ccm_helper_functions__check_even_square(__pyx_v_tmp); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 209, __pyx_L1_error)
  __pyx_t_7 = (!__pyx_t_8);
  if (__pyx_t_7) {
/* … */
  }
+210:         tmp = _make_even_square(tmp)
    __pyx_t_6 = __pyx_f_7nanopyx_4core_8analysis_20ccm_helper_functions__make_even_square(__pyx_v_tmp); if (unlikely(!__pyx_t_6.memview)) __PYX_ERR(0, 210, __pyx_L1_error)
    __PYX_XCLEAR_MEMVIEW(&__pyx_v_tmp, 1);
    __pyx_v_tmp = __pyx_t_6;
    __pyx_t_6.memview = NULL;
    __pyx_t_6.data = NULL;
+211:         img_ref = tmp[0]
    __pyx_t_9.data = __pyx_v_tmp.data;
    __pyx_t_9.memview = __pyx_v_tmp.memview;
    __PYX_INC_MEMVIEW(&__pyx_t_9, 1);
    {
    Py_ssize_t __pyx_tmp_idx = 0;
    Py_ssize_t __pyx_tmp_stride = __pyx_v_tmp.strides[0];
        __pyx_t_9.data += __pyx_tmp_idx * __pyx_tmp_stride;
}

__pyx_t_9.shape[0] = __pyx_v_tmp.shape[1];
__pyx_t_9.strides[0] = __pyx_v_tmp.strides[1];
    __pyx_t_9.suboffsets[0] = -1;

__pyx_t_9.shape[1] = __pyx_v_tmp.shape[2];
__pyx_t_9.strides[1] = __pyx_v_tmp.strides[2];
    __pyx_t_9.suboffsets[1] = -1;

__PYX_XCLEAR_MEMVIEW(&__pyx_v_img_ref, 1);
    __pyx_v_img_ref = __pyx_t_9;
    __pyx_t_9.memview = NULL;
    __pyx_t_9.data = NULL;
 212: 
+213:     return _calculate_slice_ccm(img_ref, img_slice)
  __pyx_t_9 = __pyx_f_7nanopyx_4core_8analysis_3ccm__calculate_slice_ccm(__pyx_v_img_ref, __pyx_v_img_slice); if (unlikely(!__pyx_t_9.memview)) __PYX_ERR(0, 213, __pyx_L1_error)
  __pyx_r = __pyx_t_9;
  __pyx_t_9.memview = NULL;
  __pyx_t_9.data = NULL;
  goto __pyx_L0;
 214: 
+215: def calculate_ccm_polar(np.ndarray img_slice, np.ndarray img_ref): # TODO DEPRECATED?
/* Python wrapper */
static PyObject *__pyx_pw_7nanopyx_4core_8analysis_3ccm_11calculate_ccm_polar(PyObject *__pyx_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
PyDoc_STRVAR(__pyx_doc_7nanopyx_4core_8analysis_3ccm_10calculate_ccm_polar, "\n    Function used to generate a cross correlation matrix of an image against a reference image where both are to be expressed in polar coordinates (theta,r)\n    Cross correlation values are normalized by the minimum and maximum Pearson's correlation between the two polar images.\n    Rotation in cartesian space will show as translation in the theta dimension. \n    :param img_slice: numpy array with shape (y, x)\n    :param img_ref: numpy array with shape (y, x)\n    :return: numpy array with shape (360,r), corresponding to the cross correlation matrix in polar coordinates\n    ");
static PyMethodDef __pyx_mdef_7nanopyx_4core_8analysis_3ccm_11calculate_ccm_polar = {"calculate_ccm_polar", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_7nanopyx_4core_8analysis_3ccm_11calculate_ccm_polar, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_7nanopyx_4core_8analysis_3ccm_10calculate_ccm_polar};
static PyObject *__pyx_pw_7nanopyx_4core_8analysis_3ccm_11calculate_ccm_polar(PyObject *__pyx_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
  PyArrayObject *__pyx_v_img_slice = 0;
  PyArrayObject *__pyx_v_img_ref = 0;
  #if !CYTHON_METH_FASTCALL
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  #endif
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("calculate_ccm_polar (wrapper)", 0);
  #if !CYTHON_METH_FASTCALL
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args);
  if (unlikely((__pyx_nargs < 0))) __PYX_ERR(0, 215, __pyx_L3_error)
  #endif
  #endif
  __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
  {
    PyObject **__pyx_pyargnames[] = {&__pyx_n_s_img_slice,&__pyx_n_s_img_ref,0};
  PyObject* values[2] = {0,0};
    if (__pyx_kwds) {
      Py_ssize_t kw_args;
      switch (__pyx_nargs) {
        case  2: values[1] = __Pyx_Arg_FASTCALL(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = __Pyx_NumKwargs_FASTCALL(__pyx_kwds);
      switch (__pyx_nargs) {
        case  0:
        if (likely((values[0] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_img_slice)) != 0)) {
          (void)__Pyx_Arg_NewRef_FASTCALL(values[0]);
          kw_args--;
        }
        else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 215, __pyx_L3_error)
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_img_ref)) != 0)) {
          (void)__Pyx_Arg_NewRef_FASTCALL(values[1]);
          kw_args--;
        }
        else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 215, __pyx_L3_error)
        else {
          __Pyx_RaiseArgtupleInvalid("calculate_ccm_polar", 1, 2, 2, 1); __PYX_ERR(0, 215, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        const Py_ssize_t kwd_pos_args = __pyx_nargs;
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "calculate_ccm_polar") < 0)) __PYX_ERR(0, 215, __pyx_L3_error)
      }
    } else if (unlikely(__pyx_nargs != 2)) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
      values[1] = __Pyx_Arg_FASTCALL(__pyx_args, 1);
    }
    __pyx_v_img_slice = ((PyArrayObject *)values[0]);
    __pyx_v_img_ref = ((PyArrayObject *)values[1]);
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("calculate_ccm_polar", 1, 2, 2, __pyx_nargs); __PYX_ERR(0, 215, __pyx_L3_error)
  goto __pyx_L3_error;
  __pyx_L3_error:;
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_AddTraceback("nanopyx.core.analysis.ccm.calculate_ccm_polar", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_img_slice), __pyx_ptype_5numpy_ndarray, 1, "img_slice", 0))) __PYX_ERR(0, 215, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_img_ref), __pyx_ptype_5numpy_ndarray, 1, "img_ref", 0))) __PYX_ERR(0, 215, __pyx_L1_error)
  __pyx_r = __pyx_pf_7nanopyx_4core_8analysis_3ccm_10calculate_ccm_polar(__pyx_self, __pyx_v_img_slice, __pyx_v_img_ref);
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_7nanopyx_4core_8analysis_3ccm_10calculate_ccm_polar(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_img_slice, PyArrayObject *__pyx_v_img_ref) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_TraceFrameInit(__pyx_codeobj__16)
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("calculate_ccm_polar", 0);
  __Pyx_TraceCall("calculate_ccm_polar", __pyx_f[0], 215, 0, __PYX_ERR(0, 215, __pyx_L1_error));
/* … */
  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __PYX_XCLEAR_MEMVIEW(&__pyx_t_4, 1);
  __PYX_XCLEAR_MEMVIEW(&__pyx_t_5, 1);
  __PYX_XCLEAR_MEMVIEW(&__pyx_t_6, 1);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_AddTraceback("nanopyx.core.analysis.ccm.calculate_ccm_polar", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
/* … */
  __pyx_t_7 = __Pyx_CyFunction_New(&__pyx_mdef_7nanopyx_4core_8analysis_3ccm_11calculate_ccm_polar, 0, __pyx_n_s_calculate_ccm_polar, NULL, __pyx_n_s_nanopyx_core_analysis_ccm, __pyx_d, ((PyObject *)__pyx_codeobj__16)); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 215, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_calculate_ccm_polar, __pyx_t_7) < 0) __PYX_ERR(0, 215, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
/* … */
  __pyx_codeobj__16 = (PyObject*)__Pyx_PyCode_New(2, 0, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__32, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_nanopyx_core_analysis_ccm_py, __pyx_n_s_calculate_ccm_polar, 215, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__16)) __PYX_ERR(0, 215, __pyx_L1_error)
 216:     """
 217:     Function used to generate a cross correlation matrix of an image against a reference image where both are to be expressed in polar coordinates (theta,r)
 218:     Cross correlation values are normalized by the minimum and maximum Pearson's correlation between the two polar images.
 219:     Rotation in cartesian space will show as translation in the theta dimension.
 220:     :param img_slice: numpy array with shape (y, x)
 221:     :param img_ref: numpy array with shape (y, x)
 222:     :return: numpy array with shape (360,r), corresponding to the cross correlation matrix in polar coordinates
 223:     """
+224:     return np.array(_calculate_ccm_polar(img_slice, img_ref))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 224, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_array); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 224, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = __Pyx_PyObject_to_MemoryviewSlice_dsds_float(((PyObject *)__pyx_v_img_slice), PyBUF_WRITABLE); if (unlikely(!__pyx_t_4.memview)) __PYX_ERR(0, 224, __pyx_L1_error)
  __pyx_t_5 = __Pyx_PyObject_to_MemoryviewSlice_dsds_float(((PyObject *)__pyx_v_img_ref), PyBUF_WRITABLE); if (unlikely(!__pyx_t_5.memview)) __PYX_ERR(0, 224, __pyx_L1_error)
  __pyx_t_6 = __pyx_f_7nanopyx_4core_8analysis_3ccm__calculate_ccm_polar(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_6.memview)) __PYX_ERR(0, 224, __pyx_L1_error)
  __PYX_XCLEAR_MEMVIEW(&__pyx_t_4, 1);
  __pyx_t_4.memview = NULL; __pyx_t_4.data = NULL;
  __PYX_XCLEAR_MEMVIEW(&__pyx_t_5, 1);
  __pyx_t_5.memview = NULL; __pyx_t_5.data = NULL;
  __pyx_t_2 = __pyx_memoryview_fromslice(__pyx_t_6, 2, (PyObject *(*)(char *)) __pyx_memview_get_float, (int (*)(char *, PyObject *)) __pyx_memview_set_float, 0);; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 224, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __PYX_XCLEAR_MEMVIEW(&__pyx_t_6, 1);
  __pyx_t_6.memview = NULL; __pyx_t_6.data = NULL;
  __pyx_t_7 = NULL;
  __pyx_t_8 = 0;
  #if CYTHON_UNPACK_METHODS
  if (unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_7)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_7);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
      __pyx_t_8 = 1;
    }
  }
  #endif
  {
    PyObject *__pyx_callargs[2] = {__pyx_t_7, __pyx_t_2};
    __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_8, 1+__pyx_t_8);
    __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 224, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  }
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;
 225: 
+226: cdef float[:,:] _calculate_ccm_polar(float[:, :] img_slice, float[:, :] img_ref): # TODO DEPRECATED?
static __Pyx_memviewslice __pyx_f_7nanopyx_4core_8analysis_3ccm__calculate_ccm_polar(__Pyx_memviewslice __pyx_v_img_slice, __Pyx_memviewslice __pyx_v_img_ref) {
  __Pyx_memviewslice __pyx_v_polar_slice = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_polar_ref = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_r = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_calculate_ccm_polar", 0);
  __Pyx_TraceCall("_calculate_ccm_polar", __pyx_f[0], 226, 0, __PYX_ERR(0, 226, __pyx_L1_error));
/* … */
  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __PYX_XCLEAR_MEMVIEW(&__pyx_t_5, 1);
  __pyx_r.data = NULL;
  __pyx_r.memview = NULL;
  __Pyx_AddTraceback("nanopyx.core.analysis.ccm._calculate_ccm_polar", __pyx_clineno, __pyx_lineno, __pyx_filename);
  goto __pyx_L2;
  __pyx_L0:;
  if (unlikely(!__pyx_r.memview)) {
    PyErr_SetString(PyExc_TypeError, "Memoryview return value is not initialized");
  }
  __pyx_L2:;
  __PYX_XCLEAR_MEMVIEW(&__pyx_v_polar_slice, 1);
  __PYX_XCLEAR_MEMVIEW(&__pyx_v_polar_ref, 1);
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
 227: 
+228:     cdef float[:,:] polar_slice = Interpolator(img_slice).polar()
  __pyx_t_2 = __pyx_memoryview_fromslice(__pyx_v_img_slice, 2, (PyObject *(*)(char *)) __pyx_memview_get_float, (int (*)(char *, PyObject *)) __pyx_memview_set_float, 0);; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 228, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_CallOneArg(((PyObject *)__pyx_ptype_7nanopyx_4core_9transform_25interpolation_catmull_rom_Interpolator), __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 228, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_polar); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 228, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = NULL;
  __pyx_t_4 = 0;
  #if CYTHON_UNPACK_METHODS
  if (likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
      __pyx_t_4 = 1;
    }
  }
  #endif
  {
    PyObject *__pyx_callargs[1] = {__pyx_t_3, };
    __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_2, __pyx_callargs+1-__pyx_t_4, 0+__pyx_t_4);
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 228, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  }
  __pyx_t_5 = __Pyx_PyObject_to_MemoryviewSlice_dsds_float(__pyx_t_1, PyBUF_WRITABLE); if (unlikely(!__pyx_t_5.memview)) __PYX_ERR(0, 228, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_polar_slice = __pyx_t_5;
  __pyx_t_5.memview = NULL;
  __pyx_t_5.data = NULL;
+229:     cdef float[:,:] polar_ref = Interpolator(img_ref).polar()
  __pyx_t_2 = __pyx_memoryview_fromslice(__pyx_v_img_ref, 2, (PyObject *(*)(char *)) __pyx_memview_get_float, (int (*)(char *, PyObject *)) __pyx_memview_set_float, 0);; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 229, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_CallOneArg(((PyObject *)__pyx_ptype_7nanopyx_4core_9transform_25interpolation_catmull_rom_Interpolator), __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 229, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_polar); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 229, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = NULL;
  __pyx_t_4 = 0;
  #if CYTHON_UNPACK_METHODS
  if (likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
      __pyx_t_4 = 1;
    }
  }
  #endif
  {
    PyObject *__pyx_callargs[1] = {__pyx_t_3, };
    __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_2, __pyx_callargs+1-__pyx_t_4, 0+__pyx_t_4);
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 229, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  }
  __pyx_t_5 = __Pyx_PyObject_to_MemoryviewSlice_dsds_float(__pyx_t_1, PyBUF_WRITABLE); if (unlikely(!__pyx_t_5.memview)) __PYX_ERR(0, 229, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_polar_ref = __pyx_t_5;
  __pyx_t_5.memview = NULL;
  __pyx_t_5.data = NULL;
 230: 
+231:     return _calculate_slice_ccm(polar_ref, polar_slice)
  __pyx_t_5 = __pyx_f_7nanopyx_4core_8analysis_3ccm__calculate_slice_ccm(__pyx_v_polar_ref, __pyx_v_polar_slice); if (unlikely(!__pyx_t_5.memview)) __PYX_ERR(0, 231, __pyx_L1_error)
  __pyx_r = __pyx_t_5;
  __pyx_t_5.memview = NULL;
  __pyx_t_5.data = NULL;
  goto __pyx_L0;
 232: 
 233: 
+234: def calculate_ccm_logpolar(np.ndarray img_slice, np.ndarray img_ref): # TODO DEPRECATED?
/* Python wrapper */
static PyObject *__pyx_pw_7nanopyx_4core_8analysis_3ccm_13calculate_ccm_logpolar(PyObject *__pyx_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
PyDoc_STRVAR(__pyx_doc_7nanopyx_4core_8analysis_3ccm_12calculate_ccm_logpolar, "\n    Function used to generate a cross correlation matrix of an image against a reference image where both are to be expressed in logpolar coordinates (theta, log(r))\n    Cross correlation values are normalized by the minimum and maximum Pearson's correlation between the two logpolar images.\n    Rotation and scaling in cartesian space will show as translation in the theta and log(r) dimensions respectively.\n    :param img_slice: numpy array with shape (y, x)\n    :param img_ref: numpy array with shape (y, x)\n    :return: numpy array with shape (360,log(r)), corresponding to the cross correlation matrix in polar coordinates\n    ");
static PyMethodDef __pyx_mdef_7nanopyx_4core_8analysis_3ccm_13calculate_ccm_logpolar = {"calculate_ccm_logpolar", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_7nanopyx_4core_8analysis_3ccm_13calculate_ccm_logpolar, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_7nanopyx_4core_8analysis_3ccm_12calculate_ccm_logpolar};
static PyObject *__pyx_pw_7nanopyx_4core_8analysis_3ccm_13calculate_ccm_logpolar(PyObject *__pyx_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
  PyArrayObject *__pyx_v_img_slice = 0;
  PyArrayObject *__pyx_v_img_ref = 0;
  #if !CYTHON_METH_FASTCALL
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  #endif
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("calculate_ccm_logpolar (wrapper)", 0);
  #if !CYTHON_METH_FASTCALL
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args);
  if (unlikely((__pyx_nargs < 0))) __PYX_ERR(0, 234, __pyx_L3_error)
  #endif
  #endif
  __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
  {
    PyObject **__pyx_pyargnames[] = {&__pyx_n_s_img_slice,&__pyx_n_s_img_ref,0};
  PyObject* values[2] = {0,0};
    if (__pyx_kwds) {
      Py_ssize_t kw_args;
      switch (__pyx_nargs) {
        case  2: values[1] = __Pyx_Arg_FASTCALL(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = __Pyx_NumKwargs_FASTCALL(__pyx_kwds);
      switch (__pyx_nargs) {
        case  0:
        if (likely((values[0] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_img_slice)) != 0)) {
          (void)__Pyx_Arg_NewRef_FASTCALL(values[0]);
          kw_args--;
        }
        else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 234, __pyx_L3_error)
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_img_ref)) != 0)) {
          (void)__Pyx_Arg_NewRef_FASTCALL(values[1]);
          kw_args--;
        }
        else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 234, __pyx_L3_error)
        else {
          __Pyx_RaiseArgtupleInvalid("calculate_ccm_logpolar", 1, 2, 2, 1); __PYX_ERR(0, 234, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        const Py_ssize_t kwd_pos_args = __pyx_nargs;
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "calculate_ccm_logpolar") < 0)) __PYX_ERR(0, 234, __pyx_L3_error)
      }
    } else if (unlikely(__pyx_nargs != 2)) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
      values[1] = __Pyx_Arg_FASTCALL(__pyx_args, 1);
    }
    __pyx_v_img_slice = ((PyArrayObject *)values[0]);
    __pyx_v_img_ref = ((PyArrayObject *)values[1]);
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("calculate_ccm_logpolar", 1, 2, 2, __pyx_nargs); __PYX_ERR(0, 234, __pyx_L3_error)
  goto __pyx_L3_error;
  __pyx_L3_error:;
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_AddTraceback("nanopyx.core.analysis.ccm.calculate_ccm_logpolar", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_img_slice), __pyx_ptype_5numpy_ndarray, 1, "img_slice", 0))) __PYX_ERR(0, 234, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_img_ref), __pyx_ptype_5numpy_ndarray, 1, "img_ref", 0))) __PYX_ERR(0, 234, __pyx_L1_error)
  __pyx_r = __pyx_pf_7nanopyx_4core_8analysis_3ccm_12calculate_ccm_logpolar(__pyx_self, __pyx_v_img_slice, __pyx_v_img_ref);
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_7nanopyx_4core_8analysis_3ccm_12calculate_ccm_logpolar(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_img_slice, PyArrayObject *__pyx_v_img_ref) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_TraceFrameInit(__pyx_codeobj__17)
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("calculate_ccm_logpolar", 0);
  __Pyx_TraceCall("calculate_ccm_logpolar", __pyx_f[0], 234, 0, __PYX_ERR(0, 234, __pyx_L1_error));
/* … */
  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __PYX_XCLEAR_MEMVIEW(&__pyx_t_4, 1);
  __PYX_XCLEAR_MEMVIEW(&__pyx_t_5, 1);
  __PYX_XCLEAR_MEMVIEW(&__pyx_t_6, 1);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_AddTraceback("nanopyx.core.analysis.ccm.calculate_ccm_logpolar", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
/* … */
  __pyx_t_7 = __Pyx_CyFunction_New(&__pyx_mdef_7nanopyx_4core_8analysis_3ccm_13calculate_ccm_logpolar, 0, __pyx_n_s_calculate_ccm_logpolar, NULL, __pyx_n_s_nanopyx_core_analysis_ccm, __pyx_d, ((PyObject *)__pyx_codeobj__17)); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 234, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_calculate_ccm_logpolar, __pyx_t_7) < 0) __PYX_ERR(0, 234, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
 235:     """
 236:     Function used to generate a cross correlation matrix of an image against a reference image where both are to be expressed in logpolar coordinates (theta, log(r))
 237:     Cross correlation values are normalized by the minimum and maximum Pearson's correlation between the two logpolar images.
 238:     Rotation and scaling in cartesian space will show as translation in the theta and log(r) dimensions respectively.
 239:     :param img_slice: numpy array with shape (y, x)
 240:     :param img_ref: numpy array with shape (y, x)
 241:     :return: numpy array with shape (360,log(r)), corresponding to the cross correlation matrix in polar coordinates
 242:     """
+243:     return np.array(_calculate_ccm_logpolar(img_slice, img_ref))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 243, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_array); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 243, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = __Pyx_PyObject_to_MemoryviewSlice_dsds_float(((PyObject *)__pyx_v_img_slice), PyBUF_WRITABLE); if (unlikely(!__pyx_t_4.memview)) __PYX_ERR(0, 243, __pyx_L1_error)
  __pyx_t_5 = __Pyx_PyObject_to_MemoryviewSlice_dsds_float(((PyObject *)__pyx_v_img_ref), PyBUF_WRITABLE); if (unlikely(!__pyx_t_5.memview)) __PYX_ERR(0, 243, __pyx_L1_error)
  __pyx_t_6 = __pyx_f_7nanopyx_4core_8analysis_3ccm__calculate_ccm_logpolar(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_6.memview)) __PYX_ERR(0, 243, __pyx_L1_error)
  __PYX_XCLEAR_MEMVIEW(&__pyx_t_4, 1);
  __pyx_t_4.memview = NULL; __pyx_t_4.data = NULL;
  __PYX_XCLEAR_MEMVIEW(&__pyx_t_5, 1);
  __pyx_t_5.memview = NULL; __pyx_t_5.data = NULL;
  __pyx_t_2 = __pyx_memoryview_fromslice(__pyx_t_6, 2, (PyObject *(*)(char *)) __pyx_memview_get_float, (int (*)(char *, PyObject *)) __pyx_memview_set_float, 0);; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 243, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __PYX_XCLEAR_MEMVIEW(&__pyx_t_6, 1);
  __pyx_t_6.memview = NULL; __pyx_t_6.data = NULL;
  __pyx_t_7 = NULL;
  __pyx_t_8 = 0;
  #if CYTHON_UNPACK_METHODS
  if (unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_7)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_7);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
      __pyx_t_8 = 1;
    }
  }
  #endif
  {
    PyObject *__pyx_callargs[2] = {__pyx_t_7, __pyx_t_2};
    __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_8, 1+__pyx_t_8);
    __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 243, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  }
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;
 244: 
+245: cdef float[:,:] _calculate_ccm_logpolar(float[:, :] img_slice, float[:, :] img_ref): # TODO DEPRECATED?
static __Pyx_memviewslice __pyx_f_7nanopyx_4core_8analysis_3ccm__calculate_ccm_logpolar(__Pyx_memviewslice __pyx_v_img_slice, __Pyx_memviewslice __pyx_v_img_ref) {
  __Pyx_memviewslice __pyx_v_polar_slice = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_v_polar_ref = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_memviewslice __pyx_r = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_calculate_ccm_logpolar", 0);
  __Pyx_TraceCall("_calculate_ccm_logpolar", __pyx_f[0], 245, 0, __PYX_ERR(0, 245, __pyx_L1_error));
/* … */
  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __PYX_XCLEAR_MEMVIEW(&__pyx_t_4, 1);
  __pyx_r.data = NULL;
  __pyx_r.memview = NULL;
  __Pyx_AddTraceback("nanopyx.core.analysis.ccm._calculate_ccm_logpolar", __pyx_clineno, __pyx_lineno, __pyx_filename);
  goto __pyx_L2;
  __pyx_L0:;
  if (unlikely(!__pyx_r.memview)) {
    PyErr_SetString(PyExc_TypeError, "Memoryview return value is not initialized");
  }
  __pyx_L2:;
  __PYX_XCLEAR_MEMVIEW(&__pyx_v_polar_slice, 1);
  __PYX_XCLEAR_MEMVIEW(&__pyx_v_polar_ref, 1);
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
 246: 
+247:     cdef float[:,:] polar_slice = Interpolator(img_slice).polar(scale='log')
  __pyx_t_1 = __pyx_memoryview_fromslice(__pyx_v_img_slice, 2, (PyObject *(*)(char *)) __pyx_memview_get_float, (int (*)(char *, PyObject *)) __pyx_memview_set_float, 0);; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 247, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_CallOneArg(((PyObject *)__pyx_ptype_7nanopyx_4core_9transform_25interpolation_catmull_rom_Interpolator), __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 247, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_polar); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 247, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 247, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_scale, __pyx_n_u_log) < 0) __PYX_ERR(0, 247, __pyx_L1_error)
  __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_empty_tuple, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 247, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = __Pyx_PyObject_to_MemoryviewSlice_dsds_float(__pyx_t_3, PyBUF_WRITABLE); if (unlikely(!__pyx_t_4.memview)) __PYX_ERR(0, 247, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_polar_slice = __pyx_t_4;
  __pyx_t_4.memview = NULL;
  __pyx_t_4.data = NULL;
+248:     cdef float[:,:] polar_ref = Interpolator(img_ref).polar(scale='log')
  __pyx_t_3 = __pyx_memoryview_fromslice(__pyx_v_img_ref, 2, (PyObject *(*)(char *)) __pyx_memview_get_float, (int (*)(char *, PyObject *)) __pyx_memview_set_float, 0);; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 248, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyObject_CallOneArg(((PyObject *)__pyx_ptype_7nanopyx_4core_9transform_25interpolation_catmull_rom_Interpolator), __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 248, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_polar); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 248, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 248, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_scale, __pyx_n_u_log) < 0) __PYX_ERR(0, 248, __pyx_L1_error)
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_empty_tuple, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 248, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = __Pyx_PyObject_to_MemoryviewSlice_dsds_float(__pyx_t_1, PyBUF_WRITABLE); if (unlikely(!__pyx_t_4.memview)) __PYX_ERR(0, 248, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_polar_ref = __pyx_t_4;
  __pyx_t_4.memview = NULL;
  __pyx_t_4.data = NULL;
 249: 
+250:     return _calculate_slice_ccm(polar_ref, polar_slice)
  __pyx_t_4 = __pyx_f_7nanopyx_4core_8analysis_3ccm__calculate_slice_ccm(__pyx_v_polar_ref, __pyx_v_polar_slice); if (unlikely(!__pyx_t_4.memview)) __PYX_ERR(0, 250, __pyx_L1_error)
  __pyx_r = __pyx_t_4;
  __pyx_t_4.memview = NULL;
  __pyx_t_4.data = NULL;
  goto __pyx_L0;